CVR Lua Client Behaviour
Runs a Lua script against the client. Extends CVRBaseLuaBehaviour, implements IStateMachineCallbackReceiver, and forwards Unity lifecycle / collision / render / CVR-API events to matching Lua functions when they exist.
Fields
Section titled “Fields”CVRLuaScript. ScriptableObject wrapping the Lua source to execute. Required for the behaviour to run.
Local Only
Section titled “Local Only”bool. Declared on the base class. Default true. Scripts on avatars always run locally; on spawnables and worlds, non-local scripts have extra network routing.
Bound Objects
Section titled “Bound Objects”BoundObject[]. Declared on the base class. Name/UnityObject pairs injected into the Lua script at initialisation time. Each entry has:
name— lookup key used in Lua.boundThing— anyUnityEngine.Object(GameObject, component, animator, audio source, etc.).
Supported event functions
Section titled “Supported event functions”The script can implement any of the following Lua functions. They match Unity’s message names plus CVR-specific ones. The full list (from GetEventFunctionNames) is:
Awake,Start,OnDestroy,Update,FixedUpdate,LateUpdate,OnEnable,OnDisable,OnApplicationQuit,OnApplicationPause,OnApplicationFocusOnCollisionEnter,OnCollisionExit,OnCollisionStay,OnCollisionEnter2D,OnCollisionExit2D,OnCollisionStay2DOnTriggerEnter,OnTriggerExit,OnTriggerStay,OnTriggerEnter2D,OnTriggerExit2D,OnTriggerStay2DOnControllerColliderHit,OnJointBreak,OnJointBreak2DOnCanvasGroupChanged,OnRectTransformRemoved,OnRectTransformDimensionsChange,OnTransformChildrenChanged,OnTransformParentChanged,OnBeforeTransformParentChangedOnMouseDown,OnMouseEnter,OnMouseDrag,OnMouseExit,OnMouseOver,OnMouseUp,OnMouseUpAsButtonOnAnimatorMove,OnAnimatorIKOnRenderImage,OnPostRender,OnPreCull,OnPreRender,OnRenderObject,OnWillRenderObject,OnBecameVisible,OnBecameInvisibleOnParticleCollision,OnParticleSystemStopped,OnParticleTrigger,OnParticleUpdateJobScheduled- CVR API:
OnPlayerJoined,OnPlayerLeft,OnInstanceConnected,OnInstanceDisconnected,OnInstanceConnectionLost,OnInstanceConnectionRecovered,OnLocalPlayerAvatarLoaded,OnLocalPlayerAvatarClear,OnRemotePlayerAvatarLoaded,OnRemotePlayerAvatarClear,OnSpawnableCreated,OnSpawnableDestroyed - VR mode:
OnPreVRModeSwitch,OnPostVRModeSwitch,OnFailedVRModeSwitch - Late events:
OnPostFixedUpdate,OnPostUpdate,OnPostLateUpdate - State machine:
OnStateMachineEnter,OnStateMachineExit - Runtime gizmo:
OnDrawRuntimeGizmos— when defined, the component attaches aRuntimeGizmothat calls this function fromLateUpdateinside a gizmo draw context.
CVR API / collision events receive wrapped _LUAINSTANCE_* objects (e.g. _LUAINSTANCE_ScriptedPlayer, _LUAINSTANCE_ScriptedCollision, _LUAINSTANCE_ScriptedRenderTexture) instead of raw Unity types; see the Lua API docs for their surface.
Execution notes
Section titled “Execution notes”- Listeners are registered in
Startand torn down inOnDestroy. A listener is only added if the script defines the matching function. - Each call goes through
ExecuteEventwith a 1000ms timeout (5000ms for the initial script load / run). Exceeding the timeout marks the script as crashed. - Attempting to manually call a Unity event function (e.g. calling
Update()from Lua) raises a “Game Event function, and can’t be manually called!” error.
Related
Section titled “Related”Source
Section titled “Source”CVR-GameFiles/ABI.CCK.Components/CVRLuaClientBehaviour.cs, CVR-GameFiles/ABI.CCK.Components/CVRBaseLuaBehaviour.cs