Menu
Lumberyard
Developer Guide (Version 1.12)

Entity System Script Callbacks

CryLua is deprecated and will be removed in a future version of Lumberyard.

This topic describes all callbacks for the Entity system. Use of these callbacks functions is not obligatory, but some cases require that entities behave properly within the Lumberyard Editor. For example, the OnReset callback should be used to clean the state when a user enters or leaves the game mode within the Lumberyard Editor.

Default State Functions

Callback Function Description
OnSpawn Called after an entity is created by the Entity system.
OnDestroy Called when an entity is destroyed (like OnShutDown() gets called).
OnInit Called when an entity gets initialized via ENTITY_EVENT_INIT, and when its ScriptProxy gets initialized.
OnShutDown Called when an entity is destroyed (like OnDestroy() gets called).
OnReset Usually called when an editor wants to reset the state.
OnPropertyChange Called by Lumberyard Editor when the user changes one of the properties.

Script State Functions

Callback Function Description
OnBeginState Called during Entity.GotoState() after the state has been changed (that is, after OnEndState() is called on the old state).
OnBind Called when a child entity is attached to an entity. Parameters include:
  • script table for the child entity

OnCollision Called when a collision between an entity and something else occurs. Parameters include:
  • script table with information about the collision

OnEndState Called during Entity.GotoState() while the old state is still active and before OnBeginState() is called on the new state.
OnEnterArea Called when an entity has fully entered an area or trigger. Parameters include:
  • areaId (int)

  • fade fraction (float) This value is 1.0f if the entity has fully entered the area, or 0.0f in the case of trigger boxes.

OnEnterNearArea Called when an entity enters the range of an area. Works with Box-, Sphere- and Shape-Areas if a sound volume entity is connected. Takes OuterRadius of sound entity into account to determine when an entity is near the area.
OnLeaveArea Called when an entity has fully left an area or trigger. Parameters include:
  • areaId (int)

  • fade fraction (float) This value is always 0.0f.

OnLeaveNearArea Called when an entity leaves the range of an area. Works with Box-, Sphere- and Shape-Areas if a sound volume entity is connected. Takes OuterRadius of sound entity into account to determine when an entity is near the area.
OnMove Called whenever an entity moves through the world.
OnMoveNearArea Called when an entity moves. Works with Box-, Sphere- and Shape-Areas if a sound volume entity is connected. Takes OuterRadius of sound entity into account to determine when an entity is near the area.
OnProceedFadeArea Called when an entity has recently entered an area and fading is still in progress. Parameters include:
  • areaId (int)

  • fade fraction (float)

OnSoundDone Called when a sound stops. Parameters include:
  • soundId (int) The ID of the sound played, which was provided with the request to play the sound.

OnStartGame Called when a game is started.
OnStartLevel Called when a new level is started.
OnTimer Called when a timer expires. Parameters include:
  • timerId (int) The ID of the time, provided by Entity.SetTimer() .

  • period (int) Length of time, in milliseconds, that the timer runs

OnUnBind Called when a child entity is about to be detached from an entity. Parameters include:
  • script table for the child entity

OnUpdate Called periodically by the engine on the entity's current state. This assumes the console variable es_UpdateScript is set to 1.