Purpose: This section examines the various event triggers available within Unity that can be used to manually or automatically execute functions. A strong understanding of these triggers is crucial for adopting an event-driven code execution model.
Udon Documentation For Event Nodes
When: Activates once on the local client when the script/object is initialized and enabled.
Use Case: Initial setup logic, setting default values, or fetching references.
When: Activates when the GameObject or the UdonBehaviour component is enabled on the local client.
Use Case: Re-initializing state after an object is turned back on.
When: Activates when the GameObject or the UdonBehaviour component is disabled on the local client.
Use Case: Stopping continuous actions or releasing resources when the object is hidden.
When: Activates when the local player interacts (clicks/grabs) with the object.
Use Case: The standard "button press" trigger.
Requirements: The object requires a Collider component (non-trigger) and this function attached in the object's script.
When: Activates when a new player joins the instance.
Use Case: Spawning player-specific resources or welcoming the player.
When: Activates when a player leaves the instance.
Use Case: Cleaning up resources or updating player counts.
When: Activates when a player's capsule collider enters the object's trigger volume.
Use Case: Opening a door when a player walks near it.
Requirements: The object requires a Collider component with Is Trigger checked.
When: Activates when a player's capsule collider leaves the object's trigger volume.
Use Case: Closing a door when a player walks away.
Requirements: The object requires a Collider component with Is Trigger checked.
When: Activates when a player respawns (after falling into a kill barrier or being teleported by a respawn point).
Use Case: Resetting a player's state or inventory items upon death.
When: Activates when the local player successfully picks up the object. (IE holding the object, not neccesairly clicking trigger).
Use Case: Changing the visual appearance or material of the object when held.
Requirements: Object must have a VRC_Pickup component.
When: Activates when the local player drops the held object.
Use Case: Resetting the object's physical state or resetting its ownership.
Requirements: Object must have a VRC_Pickup component.
When: Activates when the local player presses the "Use" button (e.g., right trigger, grip button) while holding the object.
Use Case: Firing a projectile or turning on a held flashlight.
Requirements: Object must have a VRC_Pickup component.
When: Activates when the local player releases the "Use" button while holding the object.
Use Case: Stopping an action that began with OnPickupUseDown.
Requirements: Object must have a VRC_Pickup component.