Skip to main content
Version: 0.4.1

ST Networked Pool

An ST Networked Pool is a fixed set of copies of one object that every player sees the same way, like VRChat's VRCObjectPool. Use it for game pieces, tokens, balls, enemies or props that appear and disappear during a game. Scripts cannot create objects, so StageTime makes the copies when the world loads, and the pool's owner takes them out and puts them back. Add it with Add Component → StageTime → ST Networked Pool and set its template.

Field
templateThe object to copy. It becomes copy 0. Keep it inactive, where the copies should appear: the copies are made next to it, as its siblings
capacityHow many copies there are, the template included (1 to 64, default 8)
Member
TryToSpawn()Owner only. Activates a free copy for everyone and returns it. Returns null for other players, when every copy is out, or when the pool spawns too fast
Return(copy)Owner only. Deactivates a copy for everyone. Anything that is not one of this pool's spawned copies is ignored
GetCopy(index)The copy at index (0 to capacity - 1; copy 0 is the template), or null
activeCountHow many copies are out, the same for everyone
IsSpawned(copy)True if it is one of this pool's copies and is out

Copies get OnEnable when they are spawned and OnDisable when they are returned, on every device.

What a copy can hold​

Copies are part of your world, so unlike ST Object Pool copies they can hold:

Other StageTime components (seats, video players, queues, drawing surfaces, mirrors, launchers and other pools) and Visual Effects are not allowed in a template. The world builder reports a template that breaks these rules.

Ownership​

Only the pool's owner can spawn and return copies; everyone else sees the result. Put your script on the pool's GameObject, take ownership, and spawn once ownership has arrived:

public STNetworkedPool pool;
private bool wantSpawn;

public override void Interact()
{
if (Networking.IsOwner(gameObject) && pool.TryToSpawn() != null) return;
wantSpawn = true; // spawn when ownership arrives
Networking.SetOwner(Networking.LocalPlayer, gameObject);
}

public override void OnOwnershipTransferred(StageTimePlayer player)
{
if (player.isLocal && wantSpawn) pool.TryToSpawn();
wantSpawn = false;
}

Right after SetOwner, Networking.IsOwner is already true (so your [Synced] writes work at once), but the pool only accepts TryToSpawn and Return once ownership has arrived. Until then they return null or do nothing. When the owner leaves, the room's master becomes the pool's owner. Each copy has its own owner, like any object.

Good to know​

  • Players who join later see the copies that are out.
  • Synced values are kept when a copy is returned, as in VRChat. Reset them yourself when you spawn the copy again.
  • Don't call SetActive on a copy yourself. The pool would show it differently on other devices until that copy is spawned or returned again. Use TryToSpawn and Return.
  • Positions are not part of the pool. A spawned copy appears where it was last left on each device. Give copies an ST Object Sync (or an ST Pickup) when they move, and move them as their owner.
  • Scripts on a copy load when it is first spawned, so a big pool costs little until its copies are used. Before that, calling another script's members on the copy does nothing (with one warning).
  • TryToSpawn takes the free copy with the lowest number. VRChat's Shuffle is not available.

Limits​

Limit
Copies per pool64
Networked pools per world16
Networked objects in all copies together (a copy's GameObject with scripts, a pickup or an Object Sync counts as one)128
Script instances in all copies together128
Spawns20 a second per pool, after a burst of 64; TryToSpawn returns null over it

Every world runs on Quest and phones, so these are the limits for every world. Spawning and returning send almost nothing: the pool syncs one bit per copy.

In local preview the pool makes plain local copies, so your scripts can spawn and return them as the only player.

See the Pool deck example.