Preventing Players from Exiting a Station with disableStationExit

This example demonstrates how to prevent players from exiting a VRCStation using the default exit method, requiring a trigger or scripted event to unseat them.

How It Works:

  • Interact to toggle whether players can exit the station normally.

  • If disableStationExit is true, players cannot leave the station unless forced by a trigger or script.

  • The ForceExitPlayer() method can be called via a trigger to forcibly unseat a player.

using UdonSharp;
using UnityEngine;
using VRC.SDKBase;
using VRC.Udon;
using VRC.SDK3.Components;

public class LockStation : UdonSharpBehaviour
{
    public VRCStation station; // Assign a VRCStation in the Inspector

    public override void Interact()
    {
        if (station != null)
        {
            // Toggle the ability to exit the station
            station.disableStationExit = !station.disableStationExit;

            Debug.Log("Station exit disabled: " + station.disableStationExit);
        }
    }

    public void ForceExitPlayer()
    {
        if (station != null && Networking.LocalPlayer != null)
        {
            station.UseStation(Networking.LocalPlayer); // Forces the player to exit if seated
            Debug.Log("Player forced to exit the station.");
        }
    }
}

Last updated