OnTriggerStay Event

Definition

function OnTriggerStay(otherActorName)

end

Description

This event is specific to the trigger object. Suppose a script that has an OnTriggerStay(otherActorName) event is attached to a trigger object. In this case, the OnTriggerStay(otherActorName) event is called as long as the main character or a prefab instance that has dynamic physics is being placed inside the trigger. For example, if the main character is being placed in the trigger for 1 second and the frame rate is 30, this event will be called 30 times per second.

Parameter

otherActorName
This parameter is automatically sent to OnTriggerStay event by Vanda engine. If a prefab instance that has dynamic physics is being placed inside the trigger, the name of its physics actor is sent to the OnTriggerStay event. If the main character of the game is being placed inside the trigger, the value nil is sent to the OnTriggerStay event.

Example 1

function OnTriggerStay(otherActorName)
    PrintConsole("\nOnTriggerStay() Event was called")
end
Assume that this script is attached to a trigger called “trigger1”. In this case, if the main character or a prefab instance that has dynamic physics is being placed inside “trigger1”, the message “nOnTriggerStay() Event was called” will be displayed.

Example 2

function OnTriggerStay(otherActorName)
    if otherActorName == nil then
          PrintConsole("\nMain character is being placed inside the trigger and OnTriggerStay() Event was called")
    else
          prefab_instance_name = GetPrefabInstanceNameFromActor(otherActorName)

          message = string.format("\nOnTriggerStay() Event was called. Prefab instance name is : %s" ,prefab_instance_name)
          PrintConsole(message)
    end
end
Assume that this script is attached to a trigger named “trigger1”. In this case, if the main character is being placed inside the “trigger1”, the message Main character is being placed inside the trigger and OnTriggerStay() Event was called” will be displayed. Otherwise, if a prefab instance that has dynamic physics is being placed inside this trigger, the name of its physics actor is sent to the OnTriggerStay event. Using the GetPrefabInstanceNameFromActor function, we find the prefab instance name that otherActorName name belongs to and display it in the console.
adminOnTriggerStay Event