Table of Contents

Class MultiplayerSpawner

Automatically replicates spawnable nodes from the authority to other multiplayer peers.

Inheritance
MultiplayerSpawner

Remarks

Spawnable scenes can be configured in the editor or through code (see MultiplayerSpawner.add_spawnable_scene).

Also supports custom node spawns through MultiplayerSpawner.spawn, calling spawn_function on all peers.

Internally, MultiplayerSpawner uses MultiplayerAPI.object_configuration_add to notify spawns passing the spawned node as the object and itself as the configuration, and MultiplayerAPI.object_configuration_remove to notify despawns in a similar way.

Properties

spawn_function

Method called on all peers when a custom MultiplayerSpawner.spawn is requested by the authority. Will receive the data parameter, and should return a Node that is not in the scene tree.

Note: The returned node should not be added to the scene with Node.add_child. This is done automatically.

var spawn_function : Callable

Property Value

Callable

Remarks

spawn_limit

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.

var spawn_limit : int = 0

Property Value

int

Remarks

  • void set_spawn_limit(int value)
  • int get_spawn_limit

spawn_path

Path to the spawn root. Spawnable scenes that are added as direct children are replicated to other peers.

var spawn_path : NodePath = NodePath("")

Property Value

NodePath

Remarks

Methods

add_spawnable_scene(String)

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 spawn_path.

void add_spawnable_scene(String path)

Parameters

path String

clear_spawnable_scenes

Clears all spawnable scenes. Does not despawn existing instances on remote peers.

void clear_spawnable_scenes

get_spawnable_scene(int)

Qualifiers: const

Returns the spawnable scene path by index.

String get_spawnable_scene(int index)

Parameters

index int

get_spawnable_scene_count

Qualifiers: const

Returns the count of spawnable scene paths.

int get_spawnable_scene_count

spawn(Variant)

Requests a custom spawn, with data passed to spawn_function on all peers. Returns the locally spawned node instance already inside the scene tree, and added as a child of the node pointed by spawn_path.

Note: Spawnable scenes are spawned automatically. MultiplayerSpawner.spawn is only needed for custom spawns.

Node spawn(Variant data)

Parameters

data Variant

Events

despawned(Node)

Emitted when a spawnable scene or custom spawn was despawned by the multiplayer authority. Only called on remote peers.

signal despawned(Node node)

Parameters

node Node

spawned(Node)

Emitted when a spawnable scene or custom spawn was spawned by the multiplayer authority. Only called on remote peers.

signal spawned(Node node)

Parameters

node Node