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.
Declaring
| Float(name, def, tip="") | void | Drag-float row. |
| Int(name, def, tip="") | void | Drag-int row. |
| Bool(name, def, tip="") | void | Checkbox. |
| String(name, def, tip="") | void | Text box. |
| Vec3f(name, def, tip="") | void | Three-component drag row. |
| EntityRef(name, tip="") | void | Slot another entity is dragged onto, from the Scene Hierarchy. |
| AssetRef(name, AssetType, tip="") | void | Asset 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.
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) | float | The 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) | Entity | Resolves the stored id now. Invalid when unassigned, destroyed, or not in this scene. |
| GetFieldAsset(name, fallback="") | std::string | Path 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 / Vec3 | value | Stored inline in the scene file. |
| Entity | reference | The target's id (IDComponent::ID) — a raw handle would not survive a scene reload or Play/Stop, which rebuild the registry. |
| Asset | reference | The 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. |
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.
Deklarowanie
| Float(name, def, tip="") | void | Wiersz przeciąganej liczby zmiennoprzecinkowej. |
| Int(name, def, tip="") | void | Wiersz przeciąganej liczby całkowitej. |
| Bool(name, def, tip="") | void | Checkbox. |
| String(name, def, tip="") | void | Pole tekstowe. |
| Vec3f(name, def, tip="") | void | Wiersz z trzema składowymi. |
| EntityRef(name, tip="") | void | Slot, na który przeciągasz inną encję z Scene Hierarchy. |
| AssetRef(name, AssetType, tip="") | void | Wybó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ć.
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) | float | Ustawiona 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) | Entity | Rozwią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 / Vec3 | wartość | Zapisywane bezpośrednio w pliku sceny. |
| Entity | odwołanie | Id celu (IDComponent::ID) — surowy uchwyt nie przetrwałby przeładowania sceny ani Play/Stop, które odbudowują rejestr. |
| Asset | odwołanie | Ten 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. |
Zobacz też
ScriptableEntity · NativeScriptComponent · Przewodnik po skryptach natywnych