ScriptFields class in Thread

Values a gameplay script exposes to the inspector — the engine's equivalent of Unity's [SerializeField]. There is no reflection here, so a script states its own schema by overriding ScriptableEntity::DeclareFields, and the authored values are stored on the entity's NativeScriptComponent.

virtual void DeclareFields(ScriptFields& fields)

Declaring

Float(name, def, tip="")voidDrag-float row.
Int(name, def, tip="")voidDrag-int row.
Bool(name, def, tip="")voidCheckbox.
String(name, def, tip="")voidText box.
Vec3f(name, def, tip="")voidThree-component drag row.
EntityRef(name, tip="")voidSlot another entity is dragged onto, from the Scene Hierarchy.
AssetRef(name, AssetType, tip="")voidAsset picker, filtered to that type.

Declaration order is the order the inspector draws them, so group related settings together. Re-declaring a name replaces it rather than adding a second row; an unnamed field is ignored, because nothing could read it back.

DeclareFields must be a pure description. The editor asks a throwaway instance for its schema and never calls OnCreate — so do not touch the scene, allocate, or start anything inside it.

Reading

On ScriptableEntity, from anywhere in the script:

GetFieldFloat(name, fallback=0)floatThe authored value, or fallback.
GetFieldInt(name, fallback=0)int
GetFieldBool(name, fallback=false)bool
GetFieldString(name, fallback="")std::string
GetFieldVec3(name, fallback={0,0,0})Vec3
GetFieldEntity(name)EntityResolves the stored id now. Invalid when unassigned, destroyed, or not in this scene.
GetFieldAsset(name, fallback="")std::stringPath ready for AssetManager. Empty means unassigned.

Pass the member's own default as the fallback, so the value lives in one place even when the field was never authored:

class Player : public ScriptableEntity {
public:
    void DeclareFields(ScriptFields& f) override {
        f.Float("Speed", m_Speed, "Metres per second");
        f.EntityRef("Door");
    }

    void OnCreate() override {
        m_Speed = GetFieldFloat("Speed", m_Speed);
    }

    void OnUpdate(float ts) override {
        if (Entity door = GetFieldEntity("Door"))
            door.GetComponent<TransformComponent>().Rotation.y += ts;
    }

private:
    float m_Speed = 5.0f;
};

Types

Float / Int / Bool / String / Vec3valueStored inline in the scene file.
EntityreferenceThe target's id (IDComponent::ID) — a raw handle would not survive a scene reload or Play/Stop, which rebuild the registry.
AssetreferenceThe same GUID-or-path string every other asset slot uses, so it survives the file being renamed or moved.

References resolve when you ask for them, never at load. At OnCreate time the target may not exist yet — the scene can still be loading, or its streamed cell may not have arrived. The lookup is an indexed one (Scene::FindByUUID), so calling it per frame is fine.

When a field changes in code

Type changed—The getter refuses the old value and returns your fallback instead of reinterpreting the bytes, so you get your default rather than a wrong number. The inspector resets the stored value to the declared default.
Renamed or removed—The authored value is kept, listed in the inspector under a warning with a ✕. A rename never silently throws away someone's work.
Entity references on a prefab do not survive instantiation. Instantiating a prefab gives the copy fresh ids and repairs its hierarchy, but a reference stored inside a component is not remapped — every copy keeps pointing at whatever the original pointed at. The inspector warns when a prefab's script declares one. On a plain scene entity it is safe; inside a prefab, resolve the target in code instead.

See also

ScriptableEntity · NativeScriptComponent · Native Scripting guide

ScriptFields klasa w Thread

Wartości, które skrypt gry wystawia do inspektora — odpowiednik [SerializeField] z Unity. Nie ma tu refleksji, więc skrypt sam podaje swój schemat, nadpisując ScriptableEntity::DeclareFields, a ustawione wartości są przechowywane w NativeScriptComponent encji.

virtual void DeclareFields(ScriptFields& fields)

Deklarowanie

Float(name, def, tip="")voidWiersz przeciąganej liczby zmiennoprzecinkowej.
Int(name, def, tip="")voidWiersz przeciąganej liczby całkowitej.
Bool(name, def, tip="")voidCheckbox.
String(name, def, tip="")voidPole tekstowe.
Vec3f(name, def, tip="")voidWiersz z trzema składowymi.
EntityRef(name, tip="")voidSlot, na który przeciągasz inną encję z Scene Hierarchy.
AssetRef(name, AssetType, tip="")voidWybór assetu ograniczony do tego typu.

Kolejność deklaracji to kolejność rysowania w inspektorze, więc grupuj powiązane ustawienia. Ponowna deklaracja nazwy zastępuje ją zamiast dodawać drugi wiersz; pole bez nazwy jest ignorowane, bo nic nie mogłoby go odczytać.

DeclareFields musi być czystym opisem. Edytor pyta o schemat tymczasową instancję i nigdy nie wywołuje OnCreate — więc w środku nie dotykaj sceny, nie alokuj i niczego nie uruchamiaj.

Odczyt

Na ScriptableEntity, z dowolnego miejsca skryptu:

GetFieldFloat(name, fallback=0)floatUstawiona wartość albo fallback.
GetFieldInt(name, fallback=0)int
GetFieldBool(name, fallback=false)bool
GetFieldString(name, fallback="")std::string
GetFieldVec3(name, fallback={0,0,0})Vec3
GetFieldEntity(name)EntityRozwiązuje zapisane id teraz. Nieważna, gdy nieprzypisana, zniszczona albo nie w tej scenie.
GetFieldAsset(name, fallback="")std::stringŚcieżka gotowa dla AssetManager. Pusta = nieprzypisana.

Jako fallback podawaj domyślną wartość samego pola, żeby wartość żyła w jednym miejscu, nawet gdy pole nigdy nie zostało ustawione:

class Player : public ScriptableEntity {
public:
    void DeclareFields(ScriptFields& f) override {
        f.Float("Speed", m_Speed, "Metres per second");
        f.EntityRef("Door");
    }

    void OnCreate() override {
        m_Speed = GetFieldFloat("Speed", m_Speed);
    }

    void OnUpdate(float ts) override {
        if (Entity door = GetFieldEntity("Door"))
            door.GetComponent<TransformComponent>().Rotation.y += ts;
    }

private:
    float m_Speed = 5.0f;
};

Typy

Float / Int / Bool / String / Vec3wartośćZapisywane bezpośrednio w pliku sceny.
EntityodwołanieId celu (IDComponent::ID) — surowy uchwyt nie przetrwałby przeładowania sceny ani Play/Stop, które odbudowują rejestr.
AssetodwołanieTen sam napis GUID-albo-ścieżka co w każdym innym slocie assetu, więc przetrwa zmianę nazwy lub przeniesienie pliku.

Odwołania rozwiązują się wtedy, gdy o nie prosisz, nigdy przy wczytywaniu. W chwili OnCreate cel może jeszcze nie istnieć — scena może się dopiero wczytywać albo jej strumieniowana komórka mogła jeszcze nie dotrzeć. Wyszukiwanie idzie po indeksie (Scene::FindByUUID), więc wołanie co klatkę jest w porządku.

Gdy pole zmienia się w kodzie

Zmiana typu—Getter odrzuca starą wartość i zwraca twój fallback zamiast reinterpretować bajty, więc dostajesz wartość domyślną, a nie złą liczbę. Inspektor resetuje zapisaną wartość do zadeklarowanej domyślnej.
Zmiana nazwy lub usunięcie—Ustawiona wartość zostaje, pokazana w inspektorze pod ostrzeżeniem z ✕. Zmiana nazwy nigdy po cichu nie wyrzuca czyjejś pracy.
Odwołania do encji w prefabie nie przetrwają tworzenia instancji. Utworzenie prefabu nadaje kopii nowe id i naprawia jej hierarchię, ale odwołanie zapisane w komponencie nie jest przemapowywane — każda kopia wskazuje to samo, co oryginał. Inspektor ostrzega, gdy skrypt prefabu deklaruje takie pole. Na zwykłej encji sceny jest to bezpieczne; w prefabie rozwiązuj cel w kodzie.

Zobacz też

ScriptableEntity · NativeScriptComponent · Przewodnik po skryptach natywnych