MultiplayerSpawner
Automatically replicates spawnable nodes from the authority to other multiplayer peers.
Automatically replicates spawnable nodes from the authority to other multiplayer peers.
Spawnable scenes can be configured in the editor or through code (see MultiplayerSpawner.AddSpawnableScene).
Also supports custom node spawns through MultiplayerSpawner.Spawn, calling MultiplayerSpawner.SpawnFunction on all peers.
Internally, MultiplayerSpawner uses MultiplayerApi.ObjectConfigurationAdd to notify spawns passing the spawned node as the object and itself as the configuration, and MultiplayerApi.ObjectConfigurationRemove to notify despawns in a similar way.
Declarations checked against C# SDK 1.0.0. Expand a name to see declarations and documentation.
Constructors1
MultiplayerSpawnerConstructor
public MultiplayerSpawner();Properties4
SpawnFunctionProperty
public Callable SpawnFunction { get; set; }Method called on all peers when a custom MultiplayerSpawner.Spawn is requested by the authority. Will receive the data parameter, and should return a Entity that is not in the scene tree.
Note: The returned node should not be added to the scene with Entity.AddChild. This is done automatically.
SpawnLimitProperty
public uint SpawnLimit { get; set; }Maximum number of nodes allowed to be spawned by this spawner. Includes both spawnable scenes and custom spawns.
When set to 0 (the default), there is no limit.
SpawnPathProperty
public EntityPath SpawnPath { get; set; }Path to the spawn root. Spawnable scenes that are added as direct children are replicated to other peers.
_SpawnableScenesProperty
public string[] _SpawnableScenes { get; set; }Methods11
AddSpawnableScenevoid
public void AddSpawnableScene(string path);Adds a scene path to spawnable scenes, making it automatically replicated from the multiplayer authority to other peers when added as children of the node pointed by MultiplayerSpawner.SpawnPath.
| Name | Type | Default |
|---|---|---|
path | string | — |
ClearSpawnableScenesvoid
public void ClearSpawnableScenes();Clears all spawnable scenes. Does not despawn existing instances on remote peers.
GetSpawnFunctionCallable
public Callable GetSpawnFunction();CallableGetSpawnLimituint
public uint GetSpawnLimit();uintGetSpawnPathEntityPath
public EntityPath GetSpawnPath();EntityPathGetSpawnableScenestring
public string GetSpawnableScene(int index);Returns the spawnable scene path by index.
| Name | Type | Default |
|---|---|---|
index | int | — |
stringGetSpawnableSceneCountint
public int GetSpawnableSceneCount();Returns the count of spawnable scene paths.
intSetSpawnFunctionvoid
public void SetSpawnFunction(Callable spawnFunction);| Name | Type | Default |
|---|---|---|
spawnFunction | Callable | — |
SetSpawnLimitvoid
public void SetSpawnLimit(uint limit);| Name | Type | Default |
|---|---|---|
limit | uint | — |
SetSpawnPathvoid
public void SetSpawnPath(EntityPath path);| Name | Type | Default |
|---|---|---|
path | EntityPath | — |
SpawnEntity
public Entity Spawn(Variant data = default);Requests a custom spawn, with data passed to MultiplayerSpawner.SpawnFunction on all peers. Returns the locally spawned node instance already inside the scene tree, and added as a child of the node pointed by MultiplayerSpawner.SpawnPath.
Note: Spawnable scenes are spawned automatically. MultiplayerSpawner.Spawn is only needed for custom spawns.
| Name | Type | Default |
|---|---|---|
data | Variant | default |
EntitySignals and events2
DespawnedEvent
public event MultiplayerSpawner.DespawnedEventHandler Despawned;Emitted when a spawnable scene or custom spawn was despawned by the multiplayer authority. Only called on remote peers.
| Name | Type | Default |
|---|---|---|
node | Entity | — |
SpawnedEvent
public event MultiplayerSpawner.SpawnedEventHandler Spawned;Emitted when a spawnable scene or custom spawn was spawned by the multiplayer authority. Only called on remote peers.
| Name | Type | Default |
|---|---|---|
node | Entity | — |