Background for Skyrim SE
Member of the ObjectReference script

Description

Wiki Description

Event called when the object reference is a trigger volume and has been entered.

Documentation Comment

Event received when this trigger volume is entered


Caveats

CK Wiki - Notes

  • This event can be received out of order with ObjectReference.OnTriggerLeave(...), so it's ideal to keep a count instead of a simple true/false value for when things are inside the trigger.
Int InTrigger = 0

Event OnTriggerEnter(ObjectReference akTriggerRef)
    if (InTrigger == 0)
        if akTriggerRef == Game.GetPlayer()
            InTrigger += 1
            debug.notification("Entered Trigger")
        endif
    endif
EndEvent

Event OnTriggerLeave(ObjectReference akTriggerRef)
    if (InTrigger > 0)
        if akTriggerRef == Game.GetPlayer()
            InTrigger -= 1
            debug.notification("Leaving Trigger")
        endif
    endif
EndEvent
  • If you set a trigger around a teleport door marker this event will fire for the player but not for NPCs.

  • The collision layer associated with a primitive containing the script for this event doesn't detect dead actors.

  • Trigger volumes use collision shapes to detect when objects enter them, and this counts as "ObjectReference.Is3DLoaded()." If a trigger's 3D unloads (e.g. because the trigger was disabled or moved), it may dispatch OnTriggerLeave for some or all refs that were previously detected as being inside the trigger. When the trigger's 3D reloads, it may dispatch OnTriggerEnter for some or all of those same refs.

    • If you need to move a trigger without unloading its 3D, ObjectReference.TranslateToRef(...) the trigger ref may work.
    • Strangely, when a trigger's 3D unloads and reloads, the game may fire "leave" for each ref within the trigger, but only fire "enter" for some of them. Translating the trigger afterward seems to fire "enter" for whatever refs failed to fire it upon 3D reloading.

Parameters

  1. ObjectReferenceakActionRef

    CK Wiki Description

    The ObjectReference that entered the volume.


Examples

Event OnTriggerEnter(ObjectReference akActionRef)
  Debug.Trace(akActionRef + " just entered us!")
EndEvent

Auto-Generated Example

Scriptname MyCoolScript extends ObjectReference

event OnTriggerEnter(ObjectReference akActionRef)
    Debug.trace("Event received - OnTriggerEnter: akActionRef = " + akActionRef)
endEvent

Related Pages


Additional References

View this event’s page on the Skyrim Creation Kit Wiki

Some data provided by the Skyrim Creation Kit Wiki. Licensed under the Creative Commons Attribution-ShareAlike license.