Class reference
Struct
A schema-backed container of named, typed fields with value semantics.
Description
Struct is a fixed-layout container whose fields are described by a shared schema (name, type, and optional default per field). Unlike Dictionary, a struct has value semantics: copying a struct copies its field values, and two structs compare equal when they share the same field layout and all field values are equal. Fields are accessed by name (a StringName or String) or by integer index through the [] operator. Values assigned to a field are validated against the schema and coerced to the field's declared type; incompatible values are rejected. Object fields can be typed as a native class, script class, or GDScript trait. Script class fields accept instances of that class and its subclasses; trait fields accept objects whose scripts use the trait. Object fields also accept null. Copying a struct copies object references, not the referenced objects. Changing a referenced object's properties is visible through every copy, while replacing a field affects only that struct. RefCounted objects are retained until their references are released; other objects, including Nodes, can be freed independently and should be checked with @GlobalScope.is_instance_valid() before use. Reference cycles involving structs and RefCounted objects are not collected automatically. Note: The schema itself is created and managed internally; structs are typically obtained from typed APIs or from GDScript struct declarations rather than constructed field-by-field from script.
Constructors
Operators
bool operator !=(Struct right)
Returns true if the two structs are not equal, that is, if they have a different field layout or any field value differs.
bool operator ==(Struct right)
Returns true if the two structs are equal. Structs are equal when they share the same field layout and all corresponding field values compare equal; structs with different layouts are never equal.
Variant operator [](Variant key)
Accesses a struct field. The key may be the field name (a StringName or String) or the integer field index. Assignment is validated against the struct's schema: incompatible values are rejected, and accepted values are coerced to the field's declared type.