Class MultiplayerSpawner
- Namespace
- Godot
- Assembly
- GodotSharp.dll
Spawnable scenes can be configured in the editor or through code (see AddSpawnableScene(string)).
Also supports custom node spawns through Spawn(Variant), calling SpawnFunction on all peers.
Internally, MultiplayerSpawner uses ObjectConfigurationAdd(GodotObject, Variant) to notify spawns passing the spawned node as the object
and itself as the configuration
, and ObjectConfigurationRemove(GodotObject, Variant) to notify despawns in a similar way.
public class MultiplayerSpawner : Node, IDisposable
- Inheritance
-
MultiplayerSpawner
- Implements
- Inherited Members
Constructors
MultiplayerSpawner()
public MultiplayerSpawner()
Properties
SpawnFunction
Method called on all peers when for every custom Spawn(Variant) 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 AddChild(Node, bool, InternalMode). This is done automatically.
public Callable SpawnFunction { get; set; }
Property Value
SpawnLimit
Maximum nodes that is allowed to be spawned by this spawner. Includes both spawnable scenes and custom spawns.
When set to 0
(the default), there is no limit.
public uint SpawnLimit { get; set; }
Property Value
SpawnPath
Path to the spawn root. Spawnable scenes that are added as direct children are replicated to other peers.
public NodePath SpawnPath { get; set; }
Property Value
_SpawnableScenes
public string[] _SpawnableScenes { get; set; }
Property Value
- string[]
Methods
AddSpawnableScene(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 SpawnPath.
public void AddSpawnableScene(string path)
Parameters
path
string
ClearSpawnableScenes()
Clears all spawnable scenes. Does not despawn existing instances on remote peers.
public void ClearSpawnableScenes()
GetSpawnableScene(int)
Returns the spawnable scene path by index.
public string GetSpawnableScene(int index)
Parameters
index
int
Returns
GetSpawnableSceneCount()
Returns the count of spawnable scene paths.
public int GetSpawnableSceneCount()
Returns
HasGodotClassMethod(in godot_string_name)
Check if the type contains a method with the given name. This method is used by Godot to check if a method exists before invoking it. Do not call or override this method.
protected override bool HasGodotClassMethod(in godot_string_name method)
Parameters
method
godot_string_nameName of the method to check for.
Returns
HasGodotClassSignal(in godot_string_name)
Check if the type contains a signal with the given name. This method is used by Godot to check if a signal exists before raising it. Do not call or override this method.
protected override bool HasGodotClassSignal(in godot_string_name signal)
Parameters
signal
godot_string_nameName of the signal to check for.
Returns
InvokeGodotClassMethod(in godot_string_name, NativeVariantPtrArgs, out godot_variant)
Invokes the method with the given name, using the given arguments. This method is used by Godot to invoke methods from the engine side. Do not call or override this method.
protected override bool InvokeGodotClassMethod(in godot_string_name method, NativeVariantPtrArgs args, out godot_variant ret)
Parameters
method
godot_string_nameName of the method to invoke.
args
NativeVariantPtrArgsArguments to use with the invoked method.
ret
godot_variantValue returned by the invoked method.
Returns
Spawn(Variant)
Requests a custom spawn, with data
passed to 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 SpawnPath.
Note: Spawnable scenes are spawned automatically. Spawn(Variant) is only needed for custom spawns.
public Node Spawn(Variant data = default)
Parameters
data
Variant
Returns
Events
Despawned
Emitted when a spawnable scene or custom spawn was despawned by the multiplayer authority. Only called on puppets.
public event MultiplayerSpawner.DespawnedEventHandler Despawned
Event Type
Spawned
Emitted when a spawnable scene or custom spawn was spawned by the multiplayer authority. Only called on puppets.
public event MultiplayerSpawner.SpawnedEventHandler Spawned