Skip to main content
Version: 0.4.1

ST Live Stream

Only StageTime Event Hosts can use live streams for now

Only StageTime Event Hosts can start, change or stop a live stream. You can add an ST Live Stream to your world and control it from your scripts, but for everyone else it stays idle: Play() and Stop() do nothing, and nothing is shown or heard. That includes you when you try your world with Build & Test, unless you are an Event Host. This means official StageTime Event Hosts in a room they created (and StageTime admins); StagePass hosting doesn't include live streams yet. StageTime gives Event Hosts the name of their stream.

A screen that shows a live stream, picture and sound, to everyone in the room: a concert, a talk or a show that is happening right now. When an Event Host starts a stream, every player in the room sees and hears it, and players who join later see it too. Add it with Add Component → StageTime → ST Live Stream.

Field
defaultStreamThe stream name Play() uses. Empty = Play() does nothing; call Play("name") instead
targetRendererShow the picture on this renderer (optional). Its material is not copied
texturePropertyThe texture property of the renderer's material to set. Empty = the material's main texture (for URP Lit, _BaseMap)
targetTextureAlso copy the picture into this Render Texture (optional)
audioSourcePlays the stream's sound. Empty = StageTime adds a 2D Audio Source, heard at the same level everywhere

Set at least one of targetRenderer and targetTexture, or nobody sees the picture (the world builder warns you).

How it works​

  1. An Event Host presses a button in your world, and your script calls Play() (or Play("name")).
  2. StageTime checks that they are an Event Host. If they are, every device in the room connects to the stream.
  3. When the picture arrives on a device, the stream is live there: the picture shows on your screen and the sound plays. Scripts on the same GameObject get OnLiveStreamStart.
  4. Stop() from an Event Host stops it for everyone.

Everything else follows from that:

  • Players who join later connect by themselves and see the stream that is on.
  • The stream keeps playing if the Event Host who started it leaves the room. An Event Host can stop it later.
  • Changing streams: Play("other") while a stream is on switches everyone to the other one. Calling Play with the same name connects everyone again.
  • Waiting for the stream: if the Event Host starts a stream before they begin broadcasting, every device keeps trying every few seconds (isConnecting is true, and OnLiveStreamError runs once) and goes live by itself when the broadcast begins.
  • Drops: if the connection drops, the device gets OnLiveStreamEnd, reconnects by itself and gets OnLiveStreamStart again when the picture is back.
  • It is live, not synced: each device shows the stream as it arrives, so devices can be a moment apart. There is no position to jump to, and no pause.
  • Disabled GameObject: if a script turns off the ST Live Stream's GameObject, that device stops playing; it connects again when the GameObject is turned back on.

Stream names​

Names are 1 to 64 letters, digits, - and _, such as main-stage. StageTime gives Event Hosts their stream name. A defaultStream that isn't a valid name stops the build; Play("bad name!") does nothing and logs a warning.

The picture​

  • Target Renderer: StageTime sets the live picture on the renderer without copying its material, so other objects that share the material are not changed. When the stream stops, the renderer shows its material's own texture again: use it for an "off air" poster.
  • Target Texture: the picture is copied into your Render Texture every frame, scaled to its size. Use it for a screen made of several renderers, a UI Raw Image, or effects. When the stream stops, it is cleared to black.
  • texture gives scripts the live picture while the stream is live (null otherwise).

The sound​

The sound plays from audioSource, which goes through the players' Music volume like every Audio Source in your world. Its settings (volume, Spatial Blend, distances) apply as usual: a 3D source makes the sound come from the screen. StageTime turns off its Play On Awake, so don't give it a clip you want to play when the world loads: use another Audio Source for that.

While a stream is on, StageTime gives this Audio Source the highest priority, so the event is never cut off when many sounds play; it puts your settings back when the stream stops. Give each ST Live Stream its own Audio Source. Scripts can mute it or change its volume, but StageTime keeps it playing while the stream is live: Stop() and Pause() on the Audio Source are undone.

An ST Audio Analyser can listen to the stream's Audio Source, so lights and effects react to the live sound. See the Live Stream Stage sample world.

From scripts​

public STLiveStream stream;
public GameObject hostControls; // the Go live and Stop buttons

void Update()
{
// Only Event Hosts can control the stream: show the buttons to them only.
hostControls.SetActive(stream.canControl);
}

public void GoLive() => stream.Play(); // the defaultStream, for everyone
public void StopStream() => stream.Stop();
Member
Play()Starts defaultStream for everyone. Event Hosts only, for now
Play(string)Starts the named stream for everyone, replacing the one that is on. Event Hosts only, for now
Stop()Stops the stream for everyone. Event Hosts only, for now
canControlThe local player may start, change and stop the stream (for now: StageTime Event Hosts)
isLiveThe picture and sound are playing on this device
isConnectingThis device is connecting, or waiting for the broadcast to begin
currentStreamThe name of the stream that is on, or ""
requesterThe Event Host who started or last changed the stream, or null (also once they have left)
textureThe live picture while live, or null
errorWhy the stream could not play on this device, or ""

For anyone who isn't an Event Host, Play() and Stop() do nothing and log one warning. canControl is not the same as isRoomHost: a room host who isn't a StageTime Event Host can't control a live stream. Scripts can read the other fields; they can change defaultStream but not the output fields.

Scripts on the same GameObject get these events:

EventWhenRuns on
OnLiveStreamStart()The stream went live on this device: picture and sound are playing (also after a reconnect)each device
OnLiveStreamEnd()The stream stopped or dropped on this device (it reconnects by itself while the stream is on)each device
OnLiveStreamError()The stream could not play on this device; read error. It keeps trying while the stream is oneach device

A player who joins while a stream is on gets OnLiveStreamStart when it goes live on their device.

Good to know​

  • One live stream per world. Each one is downloaded and decoded by every device in the room, which costs bandwidth and battery, so use one, and show it on more than one screen with targetTexture if you need to.
  • An ST Live Stream can't be inside an ST Object Pool or ST Networked Pool template.
  • Live streams only play inside StageTime. In Unity's Play mode nothing is shown, and a script that calls Play() or Stop() logs a warning that live streams only play inside StageTime.
  • Players need a StageTime version that supports live streams.