Extending UObject derived Classes - proletariatgames/unreal.hx GitHub Wiki

Unreal.hx allows you to extend any UObject-derived class (uextension). The syntax is very straight-forward:

package myPackage;

@:uclass
class AMyActor extends unreal.AActor {
}

The following metadata can be applied at class-level:

  • @:uname("ActualName") - exports the uextension class with the selected name. Useful for getting rid of Unreal's prefixes if you'd like. Optional
  • @:uclass - makes Haxe generate the class as a UCLASS class. You can add any properties you'd like to it

You can define any Haxe type, property or function inside a uextension class. The functions that have either @:ufunction (when the compiled code is Static instead of Script) or @:uexpose metadata, and the properties that have either @:uproperty (when the compiled code is Static) or @:uexpose metadata will be exported to Unreal. These properties and functions will need to follow the type restrictions that apply to externs.

Metadata

UCLASS metas

Unreal.hx supports any UCLASS meta using the @:uclass() syntax. Example:

@:uclass(meta=[BlueprintSpawnableComponent])

UPROPERTY metas

Unreal.hx supports any UPROPERTY meta using the @:uproperty() syntax. Example:

@:uproperty(BlueprintAssignable, Category=Game)
public var someName:FName;

If you want to replicate actor properties, see property replication

UFUNCTION metas

Unreal.hx supports any UFUNCTION meta using the @:ufunction() syntax.

Some metadata may require the definition of a _Implementation function or may not allow the function itself to be implemented. For example:

@:ufunction(BlueprintImplementableEvent)
function test():Void; // we shouldn't provide a body to this function

Referencing from C++

You can use the generated Haxe classes in C++ like you would with any C++ generated class. Haxe will name the header file as its @:uname without the unreal prefix. So for example AMyClass will become MyClass.h

C++ extends Haxe

Special caution must be taken when extending a Haxe-generated class from C++. On your class constructor, you should add this->haxeGcRef.set(this->createHaxeWrapper());:

UMyClass::UMyClass(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer) {
  this->haxeGcRef.set(this->createHaxeWrapper());
}

This is needed to initialize the Haxe wrapper and constructor. Please note that this should only be done if the direct superclass is a Haxe-generated class