Skip to main content
Supported on
Snapchat

Network Spawner

NetworkSpawner is the quickest path to spawning a networked prefab. Point it at an Instantiator and a prefab, and it handles the spawn and despawn for you.

It covers two shapes:

  • Host managed. One instance for the whole session, created and deleted by the host. Use it for something that must exist exactly once and only in a state the host drives, entered and left by the whole session together.
  • Per client. Every client gets its own instance, owned by whoever spawned it. This is the shape you want for player avatars.

Component Inputs

NameTypeDescription
InstantiatorInstantiatorThe Instantiator that performs the spawn. Required.
PrefabObjectPrefabThe prefab to spawn. Must be in the Instantiator's Prefabs list.
Host ManagedbooleanOne instance for the whole session, created and deleted by the host. Leave off to give every client its own instance, owned by whoever spawned it. Defaults to true.
Network IdstringShown when Host Managed is on. A globally unique id, the same string on every client. It lets any client clean the instance up on state exit, even after the host that created it has left. Defaults to enter_global_unique_id.
OwnershipHost Owned or UnownedShown when Host Managed is on. Who may write to the instance's store. Host Owned lets only the current host write; Unowned lets every client write. The host removes the instance on state exit either way. Defaults to Host Owned.
PersistenceEphemeral, Owner, Session, or PersistShown when Host Managed is off. How long the instance's store outlives its owner. Defaults to Owner.
Spawn LocationSceneObject (optional)Optional spawn location. Defaults to this scene object's transform.

The default enter_global_unique_id is treated as unset. If you enable Host Managed and leave it, the component logs an error and does not spawn:

A host managed NetworkSpawner needs a unique Network Id to manage "<prefab name>" across clients. Please change it

Component API

NameDescription
instanceRead-only getter. The spawned NetworkRootInfo, or null before it exists.
onSpawnedEvent, called with the NetworkRootInfo.
onDespawnedEvent, called with no arguments.

Usage

Most of the time you configure this in the Inspector and never touch it from code. When you do need to react to the spawn:

import { NetworkSpawner } from 'ConnectedFramework.lspkg/Components/NetworkSpawner';

@component
export class BallWatcher extends BaseScriptComponent {
@input
spawner!: NetworkSpawner;

onAwake() {
this.spawner.onSpawned.add((root) => {
print(`Ball spawned, owned by ${root.getOwnerUserId()}`);
});
}
}

To extend the spawn behavior, subclass it. This is what the Multiplayer Game Starter Project does for its player spawner:

import { NetworkSpawner } from 'ConnectedFramework.lspkg/Components/NetworkSpawner';

@component
export class PlayerSpawner extends NetworkSpawner {
protected onAwake(): void {
super.onAwake();
this.onSpawned.add((root) => {
// Wire the spawned avatar to scene-level references here.
});
}
}
Was this page helpful?
Yes
No