Functions

All functions

Ways of Calling

You can call UFunctions directly on the object from Lua. For example:

local my_pos = CONTROLLER:K2_GetActorLocation()

or

local my_pos = CONTROLLER.K2_GetActorLocation(CONTROLLER)

It's recommended you use the first way as it's far easier to read and takes up less space.

Functions must be called using the colon (:), not (.).

Parameters

Now what if the function has out parameters?

When a method or function has out parameters, the caller must provide a variable that will receive the output value. Inside the method or function, the value of the out parameter is assigned by the method or function itself.

To use out paramters in lua, we must first pass in a value. This can either be a real value, or an empty table. For example, we'll call APlayerController::ProjectWorldLocationToScreen which has 1 out parameter (FVector2D) and a return value (bool).

local returnValue,screenPos = CONTROLLER:ProjectWorldLocationToScreen(pos, {})
-- returnValue = the return value of the function (boolean)
-- screenPos = an out paramter called ScreenLocation (FVector2D)

Last updated