MultiplayerApi
The context for network peers, sender identity and RPC.
Connects MultiplayerPeer to high-level networking. EntityTree normally polls APIs; SetMultiplayer can assign independent APIs to separate branches. A process and an API instance are different concepts.
GetRemoteSenderId identifies the sender in the current network handler; capture it before deferred work. AnyPeer is not account authentication. Coordinate RPC configuration, relative paths and authoritative server state.
Declarations checked against C# SDK 1.0.0. Expand a name to see declarations and documentation.
Properties1
MultiplayerPeerProperty
public MultiplayerPeer MultiplayerPeer { get; set; }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 MultiplayerApi.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.
Methods14
CreateDefaultInterfaceMultiplayerApi
public static MultiplayerApi CreateDefaultInterface();Returns a new instance of the default MultiplayerAPI.
MultiplayerApiGetDefaultInterfaceStringName
public static StringName GetDefaultInterface();Returns the default MultiplayerAPI implementation class name. This is usually "SceneMultiplayer" when SceneMultiplayer is available. See MultiplayerApi.SetDefaultInterface.
StringNameGetMultiplayerPeerMultiplayerPeer
public MultiplayerPeer GetMultiplayerPeer();MultiplayerPeerGetPeersint[]
public int[] GetPeers();Returns the peer IDs of all connected peers of this MultiplayerAPI's MultiplayerApi.MultiplayerPeer.
int[]GetRemoteSenderIdint
public int GetRemoteSenderId();Sender ID in the current incoming-call context. Capture before deferred work; a client-supplied playerId field does not replace it.
intGetUniqueIdint
public int GetUniqueId();Local peer ID in the current session. The server uses 1. Not a persistent account, save or game-object ID.
intHasMultiplayerPeerbool
public bool HasMultiplayerPeer();Returns true if there is a MultiplayerApi.MultiplayerPeer set.
boolIsServerbool
public bool IsServer();Returns true if this MultiplayerAPI's MultiplayerApi.MultiplayerPeer is valid and in server mode (listening for connections).
boolObjectConfigurationAddError
public Error ObjectConfigurationAdd(ReckfellObject @object, Variant configuration);Notifies the MultiplayerAPI of a new configuration for the given object. This method is used internally by EntityTree to configure the root path for this MultiplayerAPI (passing null and a valid EntityPath as configuration). 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.
Note: This method is mostly relevant when extending or overriding the MultiplayerAPI behavior via MultiplayerApiExtension.
| Name | Type | Default |
|---|---|---|
object | ReckfellObject | — |
configuration | Variant | — |
ErrorObjectConfigurationRemoveError
public Error ObjectConfigurationRemove(ReckfellObject @object, Variant configuration);Notifies the MultiplayerAPI to remove a configuration for the given object. This method is used internally by EntityTree to configure the root path for this MultiplayerAPI (passing null and an empty EntityPath as configuration). 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.
Note: This method is mostly relevant when extending or overriding the MultiplayerAPI behavior via MultiplayerApiExtension.
| Name | Type | Default |
|---|---|---|
object | ReckfellObject | — |
configuration | Variant | — |
ErrorPollError
public Error Poll();Advances network events/API. EntityTree normally polls; coordinate manual polling with MultiplayerPoll and lifetime.
ErrorRpcError
public Error Rpc(int peer, ReckfellObject @object, StringName method, Reckfell.Collections.Array arguments = null);Sends an RPC to the target peer. The given method will be called on the remote object with the provided arguments. The RPC may also be called locally depending on the implementation and RPC configuration. See Entity.Rpc and Entity.RpcConfig.
Note: Prefer using Entity.Rpc, Entity.RpcId, or my_method.rpc(peer, arg1, arg2, ...) (in C#), since they are faster. This method is mostly useful in conjunction with MultiplayerApiExtension when extending or replacing the multiplayer capabilities.
| Name | Type | Default |
|---|---|---|
peer | int | — |
object | ReckfellObject | — |
method | StringName | — |
arguments | Reckfell.Collections.Array | null |
ErrorSetDefaultInterfacevoid
public static void SetDefaultInterface(StringName interfaceName);Sets the default MultiplayerAPI implementation class. This method can be used by modules and extensions to configure which implementation will be used by EntityTree when the engine starts.
| Name | Type | Default |
|---|---|---|
interfaceName | StringName | — |
SetMultiplayerPeervoid
public void SetMultiplayerPeer(MultiplayerPeer peer);| Name | Type | Default |
|---|---|---|
peer | MultiplayerPeer | — |
Signals and events5
ConnectedToServerEvent
public event Action ConnectedToServer;Successful client API connection signal. Does not establish account authentication, level loading or every gameplay entity being ready.
ConnectionFailedEvent
public event Action ConnectionFailed;Emitted when this MultiplayerAPI's MultiplayerApi.MultiplayerPeer fails to establish a connection to a server. Only emitted on clients.
PeerConnectedEvent
public event MultiplayerApi.PeerConnectedEventHandler PeerConnected;Emitted when this MultiplayerAPI's MultiplayerApi.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).
| Name | Type | Default |
|---|---|---|
id | long | — |
PeerDisconnectedEvent
public event MultiplayerApi.PeerDisconnectedEventHandler PeerDisconnected;Reports a peer leaving. Clean associated game data; publish final state and mutate APIs in a coordinated phase.
| Name | Type | Default |
|---|---|---|
id | long | — |
ServerDisconnectedEvent
public event Action ServerDisconnected;Emitted when this MultiplayerAPI's MultiplayerApi.MultiplayerPeer disconnects from server. Only emitted on clients.
MultiplayerApi.RpcMode
| Value | Description |
|---|---|
AnyPeer = 1 | Used with |
Authority = 2 | Used with |
Disabled = 0 | Used with |