Skip to content
Cauê Waneck edited this page Apr 2, 2018 · 7 revisions

Defining in Haxe

You can create a ustruct in Haxe by creating a typedef to UnrealStruct. Its first type parameter should point to the very same typedef that is defining it, and the second should contain the struct definition:

typedef FHaxeStruct = unreal.UnrealStruct<FHaxeStruct, [{
  @:uproperty
  var name:FString;
  @:uproperty
  var fname:FName;
}]>;

// Use the static create() function instead of operator new:
var f = FHaxeStruct.create();  // new FHaxeStruct() also works

Please note that you cannot use keywords like public, private and static in this context. All fields in a struct definition are public by default. If you must specify a private or static field, you may use the @:private or @:static metadata

Alternatively, you can extend :uextern ustructs that were defined in C++, by setting an extra parameter to the UnrealStruct:

typedef FHaxeStruct = unreal.UnrealStruct<FHaxeStruct, FSuperType, [{
  @:uproperty
  var name:FString;
  @:uproperty
  var fname:FName;
}]>;

This example will create a USTRUCT() struct FHaxeStruct : public FSuperType in C++

Limitations:

  • Only :uproperty member variables are supported.
  • Constructors are not currently supported.
  • Member functions cannot be exposed to C++. :uexpose or :ufunction do nothing.
  • Default values for uproperties are not currently supported.

Declaring C++-defined ustructs

Declaring an extern ustruct is similar to declaring any extern class (see Extern definitions. Simply add the :ustruct metadata to indicate that it is a ustruct and thus can be extended by Haxe classes.

@:umodule("MyModule")
@:glueCppIncludes("MyStruct.h")
@:uextern @:ustruct extern class FMyStruct {
  public var f:Float32;
  public var d:Float64;
  public var i32:Int32;
}