VFX Visualisers
A black stage under a spiral galaxy, ribbons of light and fireworks, all made with VFX Graph and the same for every player.
Get it from the StageTime-Worlds-Examples repository: copy the Worlds/Visualisers folder into a Unity
project that has the StageTime World SDK, and open its scene.
| Piece | Built with |
|---|---|
| Galaxy, ribbons | VFX Graphs that read the exposed SyncTime property, so their motion follows the room clock |
| Fireworks | A World-space VFX Graph with a Burst event, moved to a launch point and sent SendEvent("Burst") |
| Controls | A world-space panel: Next Preset, Fireworks and a Hue slider |
How it stays in sync
Nothing about the particles is sent over the network. The galaxy and ribbons only use SyncTime and each particle's
index, so every device computes the same picture, including for players who join late. The script syncs the look,
which effects are on and the colour, in two [Synced] fields. Fireworks go off on the clock every few seconds, at
the same moment, place and colour on every device. The Fireworks button sends a network event so everyone launches
one together.
using StageTime.SDK;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.VFX;
/// <summary>
/// Runs the VFX Visualisers room. The galaxy and the light ribbons move with the room clock (their graphs read the
/// SyncTime property StageTime sets), so every player sees the same picture without any per-frame sync. This script
/// syncs only the look: which effects are on (the preset) and the colour (hue slider). Fireworks go off on the clock
/// every few seconds on every device, and the Fireworks button sends one to everyone with a network event.
/// </summary>
public class VisualiserShow : StageTimeBehaviour
{
public VisualEffect galaxy;
public VisualEffect ribbons;
public VisualEffect fireworks;
[Tooltip("Where the clock's fireworks go off, in turn.")]
public Transform[] fireworkPoints;
[Tooltip("Where the button's fireworks go off.")]
public Transform showPoint;
public Slider hueSlider;
public TMP_Text label;
[Tooltip("Seconds between the clock's fireworks.")]
public float fireworkSeconds = 5f;
[Synced] private int preset;
[Synced] private float hue = 0.62f;
private int lastSlot = -1;
private void Start()
{
lastSlot = Slot();
Apply();
}
private void Update()
{
// Every device works out the same firework from the clock: same moment, same place, same colour.
int slot = Slot();
if (slot == lastSlot) return;
lastSlot = slot;
if (fireworkPoints.Length == 0) return;
Launch(fireworkPoints[slot % fireworkPoints.Length].position, Mathf.Repeat(hue + slot * 0.137f, 1f));
}
/// <summary>Button: the next preset (Galaxy, Ribbons, Both) for everyone.</summary>
public void NextPreset()
{
Networking.SetOwner(Networking.LocalPlayer, gameObject);
preset = (preset + 1) % 3;
Apply();
}
/// <summary>Slider → On Value Changed: the colour for everyone.</summary>
public void OnHueSlider()
{
Networking.SetOwner(Networking.LocalPlayer, gameObject);
hue = hueSlider.value;
Apply();
}
/// <summary>Button: fireworks for everyone, now.</summary>
public void Fireworks()
{
SendCustomNetworkEvent(NetworkEventTarget.All, nameof(LaunchShow));
}
public void LaunchShow()
{
if (showPoint != null) Launch(showPoint.position, Mathf.Repeat(hue + 0.5f, 1f));
}
public override void OnDeserialization()
{
Apply();
}
private int Slot() => (int)(Networking.GetServerTimeInSeconds() / fireworkSeconds);
private void Launch(Vector3 position, float colour)
{
if (fireworks == null) return;
fireworks.transform.position = position;
fireworks.SetFloat("Hue", colour);
fireworks.SendEvent("Burst");
}
private void Apply()
{
galaxy.gameObject.SetActive(preset != 1);
ribbons.gameObject.SetActive(preset != 0);
galaxy.SetFloat("Hue", hue);
ribbons.SetFloat("Hue", Mathf.Repeat(hue + 0.35f, 1f));
if (hueSlider != null) hueSlider.SetValueWithoutNotify(hue);
if (label != null)
{
string name = preset == 0 ? "Galaxy" : preset == 1 ? "Ribbons" : "Galaxy + Ribbons";
label.text = "<b>" + name + "</b>\nhue " + hue.ToString("0.00");
}
}
}