Skip to reading
GDScript Programming & Godot

OnInteraction

Edition 0.86.4.1 HF1

0.86.4.1 Hotfix 1 edition. Earlier lessons and screenshots retain their original version context; revised references and supplements describe the newer behavior.

Download PDFView PDF page
On this page

Earlier edition reference / Current 0.86.4.0 property paths > p. 350

Code example
func on_interaction(event: Dictionary = {}) -> void:
    Log(ToJSON(event))

A scene-entity verb interaction reaches its execution point.

Source table from OnInteraction, page 300
Common contextUse and limits
entityId, targetEntityId, targetKind, sceneId, playerId, characterId, verb, inventoryItemId, sourceItemId; regionId for a regionThis is the shared notification before the local verb action list. Filter both target and verb. The local list receives a related but smaller context; do not assume every key shown here is passed unchanged to every nested call.

OnTriggerEntered#

Code example
func on_trigger_entered(event: Dictionary = {}) -> void:
    Log(ToJSON(event))

The active player enters an eligible trigger/interactive-region overlap.

Source table from OnInteraction, page 300
Common contextUse and limits
triggerId, entityId, sceneId, playerId, event="enter"; regionId for a regionIn the checked 3D route, other NPC bodies do not trigger this player-entry hook. The shared event runs before local onEnter actions. Starting inside a volume can create startup contact behavior; test that case separately.

OnTriggerExited#

Code example
func on_trigger_exited(event: Dictionary = {}) -> void:
    Log(ToJSON(event))

The active player leaves an eligible trigger/interactive-region overlap.

Source table from OnInteraction, page 300
Common contextUse and limits
triggerId, entityId, sceneId, playerId, event="exit"; regionId for a regionUse it for leaving a local effect area. Teleports and room changes are not guaranteed to behave like ordinary walking out of the same live volume; perform important cleanup in the owning scene/sequence too.
Page 300 of 378Permalink
Go to page