Working with UObjects

Athenaware's Lua implemention was designed to make working with objects easy and similar to how you'd do it in C++.

Accessing Object Members

In Lua, the colon (:) and dot (.) are both used for accessing members (methods or fields) of an object. However, they have a slight difference in terms of syntax and behavior.

The dot (.) operator is used to access a field directly. It is used with the following syntax:

object.member

Here, object is the table or object, and member is the name of the field within that object. When using the dot operator.

On the other hand, the colon (:) operator is used to call table functions and explicitly pass the object itself as the first argument. It is used with the following syntax:

object:func(arguments)

Here, object is the object, func is the name of the function within the object, and arguments are the arguments to be passed to the function.

Members/fields can also be modified from Lua:

local vec = FVector()
vec.X = 123.0
vec.Y = 0
vec.Z = 12

Construction

Constructing structs can be achieved by "calling" the pre-defined ScriptStruct with your supplied parameters. The order of which the parameters are layed out in the struct is the same order you'll supply it in the constructor. For example:

The FVector struct is defined as followed in UE4:

Creating an instance of an FVector, we'd do the following:

Object Validity

All UObjects held in lua are weak references. In order to check if the object is valid, you can use UObject::IsValid. This function will return true or false depending on whether or not the function is a valid UObject.

UObject::IsA

Check if an object is of a type of class. Returns true if it is, false if not.

Last updated