Synced Countdown Timer
A simple network-synced countdown timer you can start from an interact button.
Category: Networking Systems
UdonSharp Script
using UdonSharp;
using UnityEngine;
using TMPro;
using VRC.SDKBase;
using VRC.Udon;
public class SyncedCountdownTimer : UdonSharpBehaviour
{
public TextMeshProUGUI timerText;
public float durationSeconds = 30f;
[UdonSynced] private float endTime;
[UdonSynced] private bool isRunning;
public override void Interact()
{
VRCPlayerApi localPlayer = Networking.LocalPlayer;
if (localPlayer == null) return;
Networking.SetOwner(localPlayer, gameObject);
endTime = Time.time + durationSeconds;
isRunning = true;
RequestSerialization();
UpdateDisplay();
}
public override void OnDeserialization()
{
UpdateDisplay();
}
private void Update()
{
if (!isRunning) return;
float remaining = endTime - Time.time;
if (remaining <= 0f)
{
isRunning = false;
remaining = 0f;
}
if (timerText != null)
{
timerText.text = "Timer: " + Mathf.CeilToInt(remaining).ToString();
}
}
private void UpdateDisplay()
{
if (timerText == null) return;
if (!isRunning)
{
timerText.text = "Timer: 0";
return;
}
float remaining = Mathf.Max(0f, endTime - Time.time);
timerText.text = "Timer: " + Mathf.CeilToInt(remaining).ToString();
}
}
Setup
- Add script to a button object with
VRC_Interactable. - Create a TextMeshProUGUI label and assign it to
timerText. - Set
durationSeconds.
Extra Tips and Troubleshooting
Tips and Tricks
- Use short, readable timer durations for social activities.
- Pair timer completion with audio cue for clarity.
Troubleshooting
- If timer text does not update, verify TextMeshPro reference assignment.
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.
