I'm a doctor, not a mechanic
Structs
A struct (or structure) is a composite data type in UnrealScript, that can contain multiple member variables of (almost) any type, including another struct type. Structs are not reference types, that means a variable of a struct type actually contains the struct data itself, not a reference to the struct data. This imposes an important restriction on struct types: a struct may not directly or indirectly contain a variable of that same struct type.
Note: The compiler will probably not complain about a struct violating this restriction. However, if the struct type is used to declare any class or local variables or function parameters or return types, the compiler will likely crash as it attempts to allocate an infinite amount of memory!
Contents
Declaration syntax
The general syntax of a struct declaration is:
struct [modifiers] structname [extends parentstruct] { ... };
Like enums, struct declarations may appear either as standalone declaration, in which case they must be followed by a semicolon, or as inline declaration instead of the type specification in variable declarations. Struct declarations may be contained in other struct declarations, both standalone or in variable declarations. There is no difference between declaring a struct at the class level and within another struct or between a standalone and inline declaration, in all cases the struct is a direct member of the class.
Remember that all members of an UnrealScript class share the same namespace. A struct declaration may hide any member of a parent class if it has the same name.
Modifiers
Struct modifiers are not available in Unreal Engine 1. Most struct modifiers are related to native code.
- 2 – The modifier is available in Unreal Engine 2.
- 3 – The modifier is available in Unreal Engine 3.
- 3+ – The modifier is available in later Unreal Engine 3 versions, such as the UDK.
Modifiers affecting UnrealEd
- long2[confirm]
- Specifies that the struct contains many members and should not be examined when generating a value string for struct variables in UnrealEd's Actor properties window. Usually structs like Vector are displayed as "(X=1.2,Y=3.4,Z=5.6)", but with the long modifier only "(...)" is displayed.
Modifiers affecting values
- strictconfig3
- ?
Other modifiers
- atomic3
-
Please help improve this article or section by expanding it. |
- atomicwhencooked3
-
Please help improve this article or section by expanding it. |
- export2,3
- This struct is supposed to be exported to native headers.
- immutable3
-
Please help improve this article or section by expanding it. |
- immutablewhencooked3
-
Please help improve this article or section by expanding it. |
- init2,3
-
Please help improve this article or section by expanding it. |
- native2,3
- This struct includes native logic.
- transient2,3
-
Please help improve this article or section by expanding it. |
- {native type name}3
- The type to use in native code instead of this struct type. This is mainly a hack in Unreal Engine 3 to declare variables in UnrealScript with types the UnrealScript language does not provide. There are only three instances of this syntax in UT3. The structs Object.qword and Object.double represent the native types QWORD and DOUBLE respectively, and the struct UIEditorOptions.ViewportDimension represents the native type WxRect.
Member declarations
Struct members are declared like class variables. A variable group name or certain variable modifiers don't make sense for struct members, though.
Default member values
By default all struct member variables are initialized with the null value of the corresponding type.
Starting with Unreal Engine 3, struct members can also have a default value other than the corresponding null value. This can be defined in a structdefaultproperties block inside the struct declaration. A good example is the LinearColor struct from UT3:
// A linear color. struct immutable LinearColor { var() float R, G, B, A; structdefaultproperties { A=1.f } };
LinearColor declared four members of type float. The default value of member A is defined to be 1.0
, while all other members keep 0.0
as their default value. This means, whenever a variable of type LinearColor is declared, its A component already contains the value 1.0
, while the R, G, and B components have the value 0.0
.
Native struct code
Like native classes, some structs in Unreal Engine 2 and 3 games may contain native code snippets in UnrealScript. These declarations do not affect UnrealScript directly, but they are exported when auto-generating native headers while compiling UnrealScript classes. In UT2004 there are only two struct like this, GUI.GUITreeNode and GUIMultiColumnList.MultiColumnSortData. In Unreal Engine 3 games this is a much more common sight, especially in UI-related classes.
In Unreal Engine 2 native struct code is enclosed in a cppstruct block. Unreal Engine 3 uses a structcpptext block instead.
Accessing structs
Accessing a struct is as easily as accessing a class, here's an example.
class A extends Actor; var() LinearColor RedColor; // Modify RedColor at Runtime rather than on defaultproperties. event PreBeginPlay() { super.PreBeginPlay(); // Call the parent(i.e. Actor) PreBeginPlay() event RedColor.R = 1.0; // Make RedColor really red, assuming A is 1.0 and G and B are 0.0. }
Declarations | Preprocessor • Classes • Interfaces • Cpptext • Constants • Enums • Structs • Variables (Metadata) • Replication block • Operators • Delegates • Functions • States • Defaultproperties (Subobjects) |
---|---|
Types | bool • byte • float • int • name • string • Object • Class • Enums • Structs (Vector ⋅ Rotator ⋅ Quat ⋅ Color) • Static arrays • Dynamic arrays • Delegates • Typecasting |
Literals | Boolean • Float • Integer • Names • Objects (None ⋅ Self) • Vectors • Rotators • Strings |
Flow | GoTo • If • Assert • Return • Stop • Switch • While • Do...Until • For • ForEach • Break • Continue |
Specifiers | Super • Global • Static • Default • Const |
UnrealScript | Syntax • .UC • .UCI • .UPKG • Comments • #directives • Native |