Skip to content
Dan Ogles edited this page Nov 5, 2015 · 2 revisions

Declaring UENUMs in Haxe

You declare a UENUM using the :uenum metadata. Any UENUM properties can be specified as parameters of :uenum, similarly to how :uclass works.

@:uenum(BlueprintType) enum EJumpType {
  Normal;
  DoubleJump;
  WallJump;
}

@:uclass class MyCharacter extends ACharacter {
  // Make this function available to call from Blueprints, with the JumpType as a pin!
  @:ufunction(BlueprintCallable, Category=Jumping)
  public function PlayJump(jumpType:EJumpType) {
    ...
  }
}

You can also use :umeta to specify properties on each enum value:

@:uenum(BlueprintType) enum ETestHxEnumClass {
  @:umeta(DisplayName="First Entry") E_1st;
  @:umeta(DisplayName="Second Entry") E_2nd;
  @:umeta(DisplayName="Third Entry") E_3rd;
}

Declaring C++ Enums externs

On your /Externs folder, it's possible to define extern C++ enums. Since there are numerous ways to define an enum, one must look at the enum definition and determine some properties.

namespace SomeNamespace {
  enum Value {
    One, Two, Three
  };
}

The above enum would be translated like:

@:glueCppIncludes("path/to/enum/header.h")
@:uname("SomeNamespace.Value")
@:uextern extern enum MyHaxeName {
  One;
  Two;
  Three;
}

Haxe will be smart enough to determine that it needs to use a namespace on these cases.

If the enum is a C++11 enum class:

namespace AnotherNamespace {
  enum class MyEnum : uint8 {
    One, Two, Three
  }
};

Then the metadata @:class must be included:

@:glueCppIncludes("path/to/enum/header.h")
@:uname("AnotherNamespace.MyEnum")
@:uextern @:class extern enum MyEnum {
  One;
  Two;
  Three;
}