Player Count Display

Display current player count in a text label.

Category: UI Systems

UdonSharp Script

using UdonSharp;
using UnityEngine;
using TMPro;
using VRC.SDKBase;
using VRC.Udon;

public class PlayerCountDisplay : UdonSharpBehaviour
{
    public TextMeshProUGUI playerCountText;

    private void Start()
    {
        UpdateDisplay();
    }

    public override void OnPlayerJoined(VRCPlayerApi player)
    {
        UpdateDisplay();
    }

    public override void OnPlayerLeft(VRCPlayerApi player)
    {
        UpdateDisplay();
    }

    private void UpdateDisplay()
    {
        if (playerCountText == null) return;
        playerCountText.text = "Players: " + VRCPlayerApi.GetPlayerCount().ToString();
    }
}

License:

Setup

  1. Add script to any manager object.
  2. Assign TextMeshProUGUI field.
  3. Test by joining with multiple clients.

Extra Tips and Troubleshooting

Tips and Tricks

  • Place count displays in lobby or information walls.
  • Combine with max capacity text for event management.

Troubleshooting

  • If count is stale, verify player join/left events are firing in your setup.

Related Content

Prefab Setup Notes

Import the prefab or script into a throwaway test scene before adding it to a live world. Confirm inspector references, ownership behavior, sync, triggers, UI hooks, and audio or object links before moving it into the production scene.

Testing Checklist

  • Test once as a local player and again with a second client or late joiner if the behavior can affect more than one player.
  • Confirm ownership, sync, trigger zones, UI references, and audio or object references are assigned intentionally.
  • Check desktop and VR interaction distance so players can actually use the feature in context.
  • Keep a backup of the scene before changing prefabs, UdonBehaviours, or serialized references.

Related Pages

Official References