Skip to content
Cauê Waneck edited this page Nov 18, 2015 · 4 revisions

Unreal provides some core APIs for types like String, Array, Map, etc that mirror in some degree the functionality of Haxe types. Most of them aren't automatically converted to Haxe types, but there is effort to make this conversion happen as easily as possible

FString, FText and FName

The three String types in Unreal are normal Haxe wrappers - like any other Struct wrapper in ue4hx. As such, there is no special handling on the ue4hx internals for them. However, to make usage easier, these classes are actually Haxe abstracts whose underlying types are the actual wrappers. These abstracts add some extra functionality that allow automatic conversion to and from normal Haxe Strings.

Conversion

From To Expression
FString String myFstring.toString()
FText String myFtext.toString()
FName String myFname.toString()
String FString new FString(myString)*
String FText new FText(myString)*
String FName new FName(myString)*

* - These conversions can be done automatically if the types are correctly typed

Warning: Since these types aren't really String, you must be careful when setting them via reflection. The automatic conversion only work at compile-time, so one must manually create an instance of either FString, FText or FName before setting them e.g. Reflect.setProperty(myObject, "myFStringField", new FString("Some text here"))

TArray

Like the String types in Unreal, TArray is a Haxe abstract over a simple templated struct wrapper [TODO]. It exposes a simplified but similar API to Haxe Arrays.

Creating a TArray in Haxe

Creating a TArray is really simple:

var playerList:TArray<APlayerController> = TArray.create();

As with any templated function call [TODO], you can also use unreal.TypeParam to help typing:

var playerList = TArray.create(new unreal.TypeParam<APlayerController>());

Note that unreal.TypeParam is a dummy type that only helps with typing. It doesn't allocate a new type and has the exact same performance as typing like above

Using a TArray

TArrays work pretty much like Haxe arrays now. You can access them like

arr[i] 

and you can set like

arr[i]=10

You can now iterate through TArrays with for loops

for(player in playerList) {}

Function usage:

We've implemented functions for TArray with haxe syntax,so use

playerList.push(player)

rather than

playerList.Push(player))

You can check out TArray.hx to see what is currently implemented from UE4 and for several new helpful functions like toArray and mapToArray.

Performance considerations

Using TArrays is slow. Every time an index getter is accessed, a new Haxe wrapper for the underlying type is created (unless it's a basic type). Also there is some cost associated with the templated code generation for Haxe which also impacts on the performance. Haxe arrays are encouraged to be used whenever performance is critical and no garbage collection issues [TODO] are there