You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: documentation/Components.md
+37-5Lines changed: 37 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,11 +4,31 @@ Stagehand introduces facilities and patterns to streamline working with componen
4
4
5
5
## Defining and Registering Components
6
6
7
-
Through macros, boilerplate-free component definition and registration of components is possible. The macros also handle the per-component setup of [automatic change detection](ChangeDetection.md) behind the scenes.
8
-
7
+
Through macros, boilerplate-free component definition and registration of components is possible. The macros also handle the per-component setup of [automatic change detection](ChangeDetection.md) behind the scenes. Appending an underscore to a macro name (e.g., `FLOAT_` instead of `FLOAT`) opts out of change detection for that component.
9
8
10
9
### Manually defined & registered components
11
10
11
+
When none of the macro categories below fit your needs — for example, when defining a component that inherits from an arbitrary base class or requires custom Flecs hooks — you can register components manually using the `REGISTER` macro together with the Flecs and Stagehand APIs directly.
12
+
13
+
```cpp
14
+
// 1. Define your struct.
15
+
structVelocity {
16
+
float x = 0.0f;
17
+
float y = 0.0f;
18
+
float z = 0.0f;
19
+
};
20
+
21
+
// 2. Register it. stagehand::register_component<T>() enables GDScript get/set access.
Change detection is not set up automatically with manual registration. To add it, declare a tag struct and call `stagehand::internal::register_change_detection_for_component<T, ChangeTag>(world)` inside your `REGISTER` block.
12
32
13
33
### Primitive C++ Types
14
34
@@ -75,12 +95,16 @@ UINT64(AVeryHighInteger, 53925713520814); // Initialised with a default value.
75
95
### Other C++ Types
76
96
77
97
#### `TAG(Name)` / `TAG_(Name)`
98
+
99
+
Empty marker component for entity classification and filtering. Tags carry no data; change detection does not apply to them.
78
100
```cpp
79
101
TAG(IsPlayer); // Defines a tag component.
80
-
TAG_(IsGrounded); // Alias for TAG, no change detection applicable for tags.
102
+
TAG_(IsGrounded); // Alias for TAG; change detection is not applicable to tags.
Registers an existing C++ `enum class` as an ECS component. The optional `UnderlyingType` tells Stagehand which integer type to use for GDScript serialisation; it should match the enum's declared underlying type (defaults to `uint8_t`).
84
108
```cpp
85
109
enumclassAIState { Idle, Patrol, Chase };
86
110
ENUM(AIState); // Defaults to uint8_t underlying type.
@@ -93,24 +117,32 @@ ENUM_(Weather); // Opt out of change detection.
Multi-field aggregate struct component with automatic member reflection via Boost.PFR. All fields are individually registered with Flecs and exposed to GDScript as a `Dictionary`. The struct must be an aggregate type: no user-declared constructors, no virtual functions, and no private or protected non-static data members. All field types must be individually convertible to `godot::Variant`.
114
146
```cpp
115
147
STRUCT(PlayerStats, { float age; int rank; }); // Members are default-initialised.
116
148
STRUCT(ColoredPoint, { godot::Vector3 position = godot::Vector3(0, 0, 0); godot::Color color = godot::Color(1, 1, 1); }); // Members initialised with default values.
@@ -121,7 +153,7 @@ STRUCT_(TrackedPosition, { float x = 0.0f; float y = 0.0f; float z = 0.0f; }); /
These macros wrap Godot's built-in Variant types as components. They support both struct-based (Plain Old Data) types and class-based (handle) types.
156
+
These macros wrap Godot's built-in Variant types as components. They support both struct-based (Plain Old Data) types and class-based (handle) types. `GODOT_VARIANT` includes change detection; `GODOT_VARIANT_` opts out of it.
0 commit comments