Lua Scripting
Lua scripting allows you to add custom behavior to scene objects and substeps. Scripts are written in the Lua programming language and executed at runtime during training.
Where to use Lua
Scene object events
In the Inspector, each scene object has Lua script fields for different events:
| Event |
When it runs |
| On Init |
When the object is initialized (scene load) |
| On Touch |
When the trainee's hand touches the object |
| On Grab |
When the trainee grabs the object |
| On Release |
When the trainee releases the object |
| On Collision |
When the object collides with another object |
| On Trigger |
When an object enters the trigger zone |
| On Click |
When the object is clicked/pressed |
| On Primary Axis |
When the thumbstick/trackpad is used (Player avatar objects only) |
ExecuteLua substep
The ExecuteLua substep type runs a Lua script when the substep is reached in the training sequence. This is useful for automated actions that don't require trainee interaction.
Available functions
Object discovery
| Function |
Description |
FindObjectByName(name) |
Find a scene object by name |
FindSceneObjectsWithName(name) |
Find all objects matching name |
CloneObject(source, name) |
Create a copy of an object |
Visibility
| Function |
Description |
HideObject(obj) |
Hide object immediately |
ShowObject(obj) |
Show object immediately |
SmoothHideObject(obj) |
Fade out object |
SmoothShowObject(obj) |
Fade in object |
| Function |
Description |
SetWorldPosition(obj, x, y, z) |
Set absolute position |
SetLocalPosition(obj, x, y, z) |
Set position relative to parent |
SetParent(obj, newParent) |
Change object's parent |
SetDefaultParent(obj) |
Reset to original parent |
SetPlayerParent(tag, obj) |
Attach to player (HEAD, LeftHandTag, RightHandTag, BodyTag) |
Movement and animation
| Function |
Description |
MoveObject(obj, x, y, z) |
Move object to position |
RotateObject(obj, x, y, z) |
Rotate object |
StartInterpolateMove(obj, x, y, z, duration) |
Smoothly move object over time |
PlayAvatarAnimation(avatarObj, animName) |
Play avatar body animation |
Materials and visual effects
| Function |
Description |
ChangeMaterial(obj, materialName) |
Change object material |
ChangeMaterialColor(obj, r, g, b) |
Change material color (0-255) |
ActivateEffect(effectName, obj) |
Activate a VFX effect |
InitEffect(effectName, obj, x, y, z) |
Initialize effect at position |
Available VFX effects: spotLight, fireEffect, fogEffect, smokeEffect, sprayEffect, magicBall, magicBallViolet, magicBallWhite
3D Text
| Function |
Description |
InitTextOnSceneObject(obj, text, size) |
Create 3D text on object |
UpdateTextOnSceneObject(obj, text) |
Update existing text |
Dialogs and UI
| Function |
Description |
ShowDialog(text) |
Show a dialog message |
ShowDialogAtAvatar(avatar, text) |
Show speech bubble at avatar |
HideAllDialogs() |
Close all open dialogs |
Audio
| Function |
Description |
PlayAudioFile(resourceId) |
Play an audio resource |
StopAudioFile() |
Stop audio playback |
Player control
| Function |
Description |
TeleportPlayer(x, y, z) |
Move player to position |
SetPlayerRotation(y) |
Set player facing direction |
SetTeleportation(enabled) |
Enable/disable teleportation |
Timing
| Function |
Description |
WaitForSeconds(seconds) |
Pause script execution |
DelayAction(seconds, function) |
Run function after delay |
Navigation
| Function |
Description |
SetCurrentSubstep(index) |
Jump to a specific substep |
SetCurrentStep(index) |
Jump to a specific step |
Translation
| Function |
Description |
GetText(key) |
Get translated text by key |
GetCurrentLanguage() |
Get current lesson language |
Debug
| Function |
Description |
UnityDebug(message) |
Print message to Unity console |
Facts system
Lua scripts can store and retrieve persistent key-value pairs using the Facts system. Facts persist across substeps within the same lesson session, allowing scripts to share state.
Editor features
The Editor provides several tools to help write Lua scripts:
- Autocomplete - function suggestions appear after typing 2+ characters
- Scene object names - autocomplete suggests object names from the current scene
- Color picker - visual color selector for RGB values
- Position gizmo - 3D position picker for coordinate values
- Syntax highlighting - color-coded Lua syntax
- Effect name dropdown - select available VFX effects from a list