MultiplayerSpawner
Automatically replicates spawnable nodes from the authority to other multiplayer peers.
MultiplayerSpawner.swift:22class MultiplayerSpawner
Spawnable scenes can be configured in the editor or through code (see addSpawnableScene(path:)
).
Also supports custom node spawns through spawn(data:)
, calling spawnFunction
on all peers.
Internally, MultiplayerSpawner
uses objectConfigurationAdd(object:configuration:)
to notify spawns passing the spawned node as the object
and itself as the configuration
, and objectConfigurationRemove(object:configuration:)
to notify despawns in a similar way.
This object emits the following signals:
Superclasses
class Node
Base class for all scene objects.
Citizens in SwiftGodot
Conformances
protocol CustomStringConvertible
A type with a customized textual representation.
protocol Equatable
A type that can be compared for value equality.
protocol Hashable
A type that can be hashed into a
Hasher
to produce an integer hash value.protocol Identifiable<ID>
A class of types whose instances hold the value of an entity with stable identity.
protocol VariantRepresentable
Types that conform to VariantRepresentable can be stored directly in
Variant
with no conversion. These include all of the Variant types from Godot (for exampleGString
,Rect
,Plane
), Godot objects (those that subclass SwiftGodot.Object) as well as the built-in Swift types UInt8, Int64 and Double.protocol VariantStorable
Types that conform to VariantStorable can be stored in a Variant and can be extracted back out of a Variant.
Types
class Signal1
Signal support.
class Signal2
Signal support.
Type members
Instance members
var despawned: Signal1
Emitted when a spawnable scene or custom spawn was despawned by the multiplayer authority. Only called on puppets.
var spawnFunction: Callable
Method called on all peers when for every custom
spawn(data:)
requested by the authority. Will receive thedata
parameter, and should return aNode
that is not in the scene tree.var spawnLimit: UInt32
Maximum nodes that is allowed to be spawned by this spawner. Includes both spawnable scenes and custom spawns.
var spawnPath: NodePath
Path to the spawn root. Spawnable scenes that are added as direct children are replicated to other peers.
var spawned: Signal2
Emitted when a spawnable scene or custom spawn was spawned by the multiplayer authority. Only called on puppets.
func addSpawnableScene(path: 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
.func clearSpawnableScenes(
) Clears all spawnable scenes. Does not despawn existing instances on remote peers.
func getSpawnableScene(index: Int32
) -> String Returns the spawnable scene path by index.
func getSpawnableSceneCount(
) -> Int32 Returns the count of spawnable scene paths.
func spawn(data: Variant
) -> Node? Requests a custom spawn, with
data
passed tospawnFunction
on all peers. Returns the locally spawned node instance already inside the scene tree, and added as a child of the node pointed byspawnPath
.