MultiplayerAPI
High-level multiplayer API interface.
MultiplayerAPI.swift:27class MultiplayerAPI
Base class for high-level multiplayer API implementations. See also MultiplayerPeer
.
By default, SceneTree
has a reference to an implementation of this class and uses it to provide multiplayer capabilities (i.e. RPCs) across the whole scene.
It is possible to override the MultiplayerAPI instance used by specific tree branches by calling the setMultiplayer(_:rootPath:)
method, effectively allowing to run both client and server in the same scene.
It is also possible to extend or replace the default implementation via scripting or native extensions. See MultiplayerAPIExtension
for details about extensions, SceneMultiplayer
for the details about the default implementation.
This object emits the following signals:
Superclasses
class RefCounted
Base class for reference-counted 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
enum RPCMode
class Signal1
Signal support.
class Signal2
Signal support.
Type members
static func createDefaultInterface(
) -> MultiplayerAPI? Returns a new instance of the default MultiplayerAPI.
static func getDefaultInterface(
) -> StringName Returns the default MultiplayerAPI implementation class name. This is usually
"SceneMultiplayer"
whenSceneMultiplayer
is available. SeesetDefaultInterface(interfaceName:)
.static func setDefaultInterface(interfaceName: StringName
) Sets the default MultiplayerAPI implementation class. This method can be used by modules and extensions to configure which implementation will be used by
SceneTree
when the engine starts.class var godotClassName: StringName
Instance members
var connectedToServer: SimpleSignal
Emitted when this MultiplayerAPI’s
multiplayerPeer
successfully connected to a server. Only emitted on clients.var connectionFailed: SimpleSignal
Emitted when this MultiplayerAPI’s
multiplayerPeer
fails to establish a connection to a server. Only emitted on clients.var multiplayerPeer: MultiplayerPeer?
The peer object to handle the RPC system (effectively enabling networking when set). Depending on the peer itself, the MultiplayerAPI will become a network server (check with
isServer
) and will set root node’s network mode to authority, or it will become a regular client peer. All child nodes are set to inherit the network mode by default. Handling of networking-related events (connection, disconnection, new clients) is done by connecting to MultiplayerAPI’s signals.var peerConnected: Signal1
Emitted when this MultiplayerAPI’s
multiplayerPeer
connects with a new peer. ID is the peer ID of the new peer. Clients get notified when other clients connect to the same server. Upon connecting to a server, a client also receives this signal for the server (with ID being 1).var peerDisconnected: Signal2
Emitted when this MultiplayerAPI’s
multiplayerPeer
disconnects from a peer. Clients get notified when other clients disconnect from the same server.var serverDisconnected: SimpleSignal
Emitted when this MultiplayerAPI’s
multiplayerPeer
disconnects from server. Only emitted on clients.func getPeers(
) -> PackedInt32Array Returns the peer IDs of all connected peers of this MultiplayerAPI’s
multiplayerPeer
.func getRemoteSenderId(
) -> Int32 Returns the sender’s peer ID for the RPC currently being executed.
func getUniqueId(
) -> Int32 Returns the unique peer ID of this MultiplayerAPI’s
multiplayerPeer
.func hasMultiplayerPeer(
) -> Bool Returns
true
if there is amultiplayerPeer
set.func isServer(
) -> Bool Returns
true
if this MultiplayerAPI’smultiplayerPeer
is valid and in server mode (listening for connections).func objectConfigurationAdd(object: Object?, configuration: Variant
) -> GodotError Notifies the MultiplayerAPI of a new
configuration
for the givenobject
. This method is used internally bySceneTree
to configure the root path for this MultiplayerAPI (passingnull
and a validNodePath
asconfiguration
). This method can be further used by MultiplayerAPI implementations to provide additional features, refer to specific implementation (e.g.SceneMultiplayer
) for details on how they use it.func objectConfigurationRemove(object: Object?, configuration: Variant
) -> GodotError Notifies the MultiplayerAPI to remove a
configuration
for the givenobject
. This method is used internally bySceneTree
to configure the root path for this MultiplayerAPI (passingnull
and an emptyNodePath
asconfiguration
). This method can be further used by MultiplayerAPI implementations to provide additional features, refer to specific implementation (e.g.SceneMultiplayer
) for details on how they use it.func poll(
) -> GodotError Method used for polling the MultiplayerAPI. You only need to worry about this if you set
multiplayerPoll
tofalse
. By default,SceneTree
will poll its MultiplayerAPI(s) for you.func rpc(peer: Int32, object: Object?, method: StringName, arguments: GArray
) -> GodotError Sends an RPC to the target
peer
. The givenmethod
will be called on the remoteobject
with the providedarguments
. The RPC may also be called locally depending on the implementation and RPC configuration. SeeNode/rpc(method:)
andrpcConfig(method:config:)
.
Subclasses
class MultiplayerAPIExtension
Base class used for extending the
MultiplayerAPI
.class SceneMultiplayer
High-level multiplayer API implementation.