Using Events to bring your VRChat world to life Edit

The VRChat Event system is a key component of creating interactive worlds in VRChat. The Event system provides access to a range of built in functionality including:

  • triggering particle systems
  • hiding and showing objects or making them active / inactive
  • adding health and damage to players (in conjunction with VRC_AddDamage)
  • triggering custom scripted methods
  • triggering animation and setting animation parameters
  • teleporting players

The primary component script for the event system is VRC_EventHandler. This is where you set up all your events and what they will do. You can then use a variety of other methods to trigger those events including timers, collision triggers, animation events, etc.

Here's an example of a quick setup to make an object visible when a user enters a trigger volume.

Event01 objects
Event group
  • The TriggerGroup has the VRC_EventHandler on it. You generally want the event handler to be at the top of the hierarchy as the children will be sending events upwards.
  • The sphere is the object will we make appear.
  • The trigger is an empty GameObject with a box collider on it. It also has a VRC_TriggerColliderEventTrigger script on it to send the event when the collision volume is entered.
  • The cube is just to help us visualize where the trigger is.

We'll start by just setting up the hierarchy of objects first.

  1. Create an empty game object with GameObject -> Create Empty.
  2. Rename the object to TriggerGroup.
  3. Select the TriggerGroup in the hierarchy panel.
  4. Use GameObject -> Create Empty Child to create an empty game object under the TriggerGroup.
  5. rename the new object to "trigger".
  6. Use GameObject -> 3D Object -> Sphere to create the Sphere object.
  7. In the hierarchy panel, drag the Sphere onto the TriggerGroup to make it a child of the TriggerGroup.
  8. Use GameObject -> 3D Object -> Cube to create the Cube object.
  9. In the hierarchy panel, drag the Cube onto the TriggerGroup to make it a child of the TriggerGroup.
  10. scale the Cube or move it down so it looks more like the platform in the example.
  11. You should now have an object hierarchy that looks like the example. You should probably add a plane as well so the player has something to stand on ...
Event01 handler

Set up the TriggerGroup to handle the events.

  1. select the TriggerGroup in the hierarchy panel.
  2. add a VRC_EventHandler script to it.
  3. set the size of the events to 1 to open up the settings for the event.
  4. the name of the event can be whatever you want but try to use CamelCase to keep the naming conventions consistent. For the example we are calling the event "ShowBall". When this event is triggered it will do all the stuff defined in the event.
  5. the event type is MeshVisibility. It's important to note that this will turn on the MeshRenderer on the Sphere rather than enabling the whole object.
  6. The Parameter Bool is set to "true". If you wanted to hide the Sphere instead you could set this to "false". Note the that other parameters are not used for this type of event.
  7. The Parameter Object should be set to the object we want to make visible. You can just drag the Sphere from the hierarchy panel onto the Parameter Object field in the Inspector to create this reference.
Event01 trigger

Set up the trigger object that will detect when the player walks into it and trigger the event. The trigger has a BoxCollider and a VRC_TriggerColliderEventTrigger on it to pass the event up to the TriggerGroup.

  1. select the trigger object and use Component -> Physics -> Box Collider to add a collider to it. Ensure that the "IsTrigger" option is checked if you don't want players to collide with this object.
  2. move the trigger object around to so it is above the Cube. You can click the little "Edit Collider" button to adjust the collider's size and shape.
  3. add a VRC_TriggerColliderEventTrigger script to the trigger object.
  4. set the Enter Event Name parameter to "ShowBall" or whatever you called the event in the VRC_EventHandler.

Turn off the visibility of the Sphere by selecting the sphere and turning off the MeshRenderer component. You need to keep the Sphere object enabled for the MeshVisibility event to work.

That's it. You just need to add a VRCWorld prefab to your scene and you should be able to test it.

Here's a summary of how this works just to be sure this is clear.

  1. The player walks into the trigger collider on the trigger object.
  2. this triggers VRC_TriggerColliderEventTrigger to send the "ShowBall" event up the hierarchy.
  3. the "ShowBall" event is received by the VRC_EventHandler on the TriggerGroup object.
  4. the "ShowBall" event turns on the MeshRenderer on the Sphere object.

If you want to go a bit further with this you could add another event for when the player leaves the trigger.

Tip: If you want to do more than one thing with the same event you can just create additional events with the same name. When the event is triggered all events with the same name will fire off in order.