Attention: Here be dragons
This is the latest
(unstable) version of this documentation, which may document features
not available in or compatible with released stable versions of Godot.
Checking the stable version of the documentation...
MultiplayerAPI¶
Inherits: RefCounted < Object
Inherited By: MultiplayerAPIExtension, SceneMultiplayer
High-level multiplayer API interface.
Description¶
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 SceneTree.set_multiplayer 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.
Properties¶
Methods¶
create_default_interface ( ) static |
|
get_default_interface ( ) static |
|
get_peers ( ) |
|
get_unique_id ( ) |
|
is_server ( ) |
|
object_configuration_add ( Object object, Variant configuration ) |
|
object_configuration_remove ( Object object, Variant configuration ) |
|
poll ( ) |
|
rpc ( int peer, Object object, StringName method, Array arguments=[] ) |
|
void |
set_default_interface ( StringName interface_name ) static |
Signals¶
connected_to_server ( )
Emitted when this MultiplayerAPI's multiplayer_peer successfully connected to a server. Only emitted on clients.
connection_failed ( )
Emitted when this MultiplayerAPI's multiplayer_peer fails to establish a connection to a server. Only emitted on clients.
peer_connected ( int id )
Emitted when this MultiplayerAPI's multiplayer_peer 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).
peer_disconnected ( int id )
Emitted when this MultiplayerAPI's multiplayer_peer disconnects from a peer. Clients get notified when other clients disconnect from the same server.
server_disconnected ( )
Emitted when this MultiplayerAPI's multiplayer_peer disconnects from server. Only emitted on clients.
Enumerations¶
enum RPCMode:
RPCMode RPC_MODE_DISABLED = 0
Used with Node.rpc_config to disable a method or property for all RPC calls, making it unavailable. Default for all methods.
RPCMode RPC_MODE_ANY_PEER = 1
Used with Node.rpc_config to set a method to be callable remotely by any peer. Analogous to the @rpc("any_peer")
annotation. Calls are accepted from all remote peers, no matter if they are node's authority or not.
RPCMode RPC_MODE_AUTHORITY = 2
Used with Node.rpc_config to set a method to be callable remotely only by the current multiplayer authority (which is the server by default). Analogous to the @rpc("authority")
annotation. See Node.set_multiplayer_authority.
Property Descriptions¶
MultiplayerPeer multiplayer_peer
void set_multiplayer_peer ( MultiplayerPeer value )
MultiplayerPeer get_multiplayer_peer ( )
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 is_server) 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.
Method Descriptions¶
MultiplayerAPI create_default_interface ( ) static
Returns a new instance of the default MultiplayerAPI.
StringName get_default_interface ( ) static
Returns the default MultiplayerAPI implementation class name. This is usually "SceneMultiplayer"
when SceneMultiplayer is available. See set_default_interface.
PackedInt32Array get_peers ( )
Returns the peer IDs of all connected peers of this MultiplayerAPI's multiplayer_peer.
int get_remote_sender_id ( )
Returns the sender's peer ID for the RPC currently being executed.
Note: If not inside an RPC this method will return 0.
int get_unique_id ( )