Skip to content
Merlin edited this page Jul 28, 2020 · 2 revisions

Making a chair to sit in

Making a chair to sit in is fairly straightforward and the VRCChair3 prefab included with the VRCSDK shows how to setup one.

All you need for a chair is a GameObject with the following components:

  1. VRC_Station with an entry and exit point set to itself or another transform that designates there the player is rooted to the station
  2. A collider, usually with IsTrigger enabled
  3. An UdonBehaviour with an Udon program that handles sitting in the station
  4. Optionally a mesh attached it that looks like a chair

The VRCSDK comes with a program that handles #3 called StationGraph, the equivalent U# code for that graph is:

public override void Interact()
{
    Networking.LocalPlayer.UseAttachedStation();
}

Detecting when a player enters or exits a station

For making vehicles it can be useful to know when a player has entered or exited a station. Udon provides events for when players enter and exit stations for the situation where you want this info. This is a bit weird in Udon currently since the UI for the VRC_Station inspector does not work correctly.

You must first have a station setup already as described above.

In order to receive the events, first you must edit the station using the debug inspector. The debug inspector can be opened by clicking the little icon next to the lock icon on the top right of the inspector and selecting the Debug option:

debug menu

Once in the debug inspector you will see 4 string variables named On Remote Player Enter Station, On Local Player Enter Station, On Remote Player Exit Station, and On Local Player Exit Station.

Both Enter Station fields must have their string value changed to _onStationEntered and both Exit Station fields must be set to _onStationExited these are case-sensitive and must have the underscore at the beginning. You can technically set other custom event names here, but I don't recommend it since VRC may not support that behavior in the future and you won't be able to get the player API of the player who entered/exited the station.

Your inspector should look like this now:

station inspector

You can now switch back to the normal inspector by going to the same drop-down you selected to switch to the debug menu and selecting Normal.

Now if you haven't already, make a U# program. Add a way to enter the station if you want, this can be done in the way noted above with the Interact event.

In order to receive the enter and exit events, you need to add these events to the behaviour, they can be added by adding this code:

public override void OnStationEntered(VRCPlayerApi player)
{
}

public override void OnStationExited(VRCPlayerApi player)
{
}

Now you can use the player variable to check what player has entered/exited the station. You can also use this to check if the player is the local player using player.isLocal.

Clone this wiki locally