Difference between revisions of "OnTriggerEnter - ObjectReference"

From the Fallout4 CreationKit Wiki
Jump to navigation Jump to search
imported>Cdcooley
 
imported>Goggle
(→‎Examples: Added example to coincide with the note about GetTriggerObjectCount())
Line 18: Line 18:
Event OnTriggerEnter(ObjectReference akActionRef)
Event OnTriggerEnter(ObjectReference akActionRef)
   Debug.Trace(akActionRef + " just entered us!")
   Debug.Trace(akActionRef + " just entered us!")
EndEvent
</source>
<br>
<source lang="papyrus">
Event OnTriggerEnter(ObjectReference akTriggerRef)
if GetTriggerObjectCount() == 1
if akTriggerRef == Game.GetPlayer()
; debug.notification("Entered Trigger")
GetLinkedRef().Activate(Game.GetPlayer())
endif
endif
EndEvent
Event OnTriggerLeave(ObjectReference akTriggerRef)
if GetTriggerObjectCount() == 0
if akTriggerRef == Game.GetPlayer()
; debug.notification("Leaving Trigger")
GetLinkedRef().Activate(Game.GetPlayer())
endif
endif
EndEvent
EndEvent
</source>
</source>

Revision as of 07:53, 26 August 2016

Member of: ObjectReference Script (Papyrus)

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

Syntax

Event OnTriggerEnter(ObjectReference akActionRef)

Parameters

Examples

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


Event OnTriggerEnter(ObjectReference akTriggerRef)
	if GetTriggerObjectCount() == 1
		if akTriggerRef == Game.GetPlayer()
		;	debug.notification("Entered Trigger")
			GetLinkedRef().Activate(Game.GetPlayer())
		endif
	endif
EndEvent

Event OnTriggerLeave(ObjectReference akTriggerRef)
	if GetTriggerObjectCount() == 0
		if akTriggerRef == Game.GetPlayer()
		;	debug.notification("Leaving Trigger")
			GetLinkedRef().Activate(Game.GetPlayer())
		endif
	endif
EndEvent

Notes

  • This event can be received out of order with OnTriggerLeave, so it's better to keep a count instead of a simple true/false value for when things are inside the trigger.
    • Note, however, that because of the way Papyrus event handling and threading works, at any given moment, your count may be inaccurate, and there is a risk of the count becoming 'stuck' over time if events are not processed correctly. If your script requires precise accuracy, use the trigger's Interaction Conditions to restrict it to just the references you care about (eg. the player), then use GetTriggerObjectCount to verify that the reference is actually in the trigger at the time it matters.
  • The trigger's Collision Layer (typically L_TRIGGER) determines what types of objects will fire OnTriggerEnter/OnTriggerLeave events when they enter the trigger. For example, actors do, statics don't.

See Also