Table of Contents

Class SceneMultiplayer

Namespace
Godot
Assembly
GodotSharp.dll

This class is the default implementation of MultiplayerApi, used to provide multiplayer functionalities in Godot Engine.

This implementation supports RPCs via Rpc(StringName, params Variant[]) and RpcId(long, StringName, params Variant[]) and requires Rpc(int, GodotObject, StringName, Array) to be passed a Node (it will fail for other object types).

This implementation additionally provide SceneTree replication via the MultiplayerSpawner and MultiplayerSynchronizer nodes, and the SceneReplicationConfig resource.

Note: The high-level multiplayer API protocol is an implementation detail and isn't meant to be used by non-Godot servers. It may change without notice.

Note: When exporting to Android, make sure to enable the INTERNET permission in the Android export preset before exporting the project or using one-click deploy. Otherwise, network communication of any kind will be blocked by Android.

public class SceneMultiplayer : MultiplayerApi, IDisposable
Inheritance
SceneMultiplayer
Implements
Inherited Members

Constructors

SceneMultiplayer()

public SceneMultiplayer()

Properties

AllowObjectDecoding

If true, the MultiplayerAPI will allow encoding and decoding of object during RPCs.

Warning: Deserialized objects can contain code which gets executed. Do not use this option if the serialized object comes from untrusted sources to avoid potential security threat such as remote code execution.

public bool AllowObjectDecoding { get; set; }

Property Value

bool

AuthCallback

The callback to execute when when receiving authentication data sent via SendAuth(int, byte[]). If the Callable is empty (default), peers will be automatically accepted as soon as they connect.

public Callable AuthCallback { get; set; }

Property Value

Callable

AuthTimeout

If set to a value greater than 0.0, the maximum amount of time peers can stay in the authenticating state, after which the authentication will automatically fail. See the PeerAuthenticating and PeerAuthenticationFailed signals.

public double AuthTimeout { get; set; }

Property Value

double

MaxDeltaPacketSize

Maximum size of each delta packet. Higher values increase the chance of receiving full updates in a single frame, but also the chance of causing networking congestion (higher latency, disconnections). See MultiplayerSynchronizer.

public int MaxDeltaPacketSize { get; set; }

Property Value

int

MaxSyncPacketSize

Maximum size of each synchronization packet. Higher values increase the chance of receiving full updates in a single frame, but also the chance of packet loss. See MultiplayerSynchronizer.

public int MaxSyncPacketSize { get; set; }

Property Value

int

RefuseNewConnections

If true, the MultiplayerAPI's MultiplayerPeer refuses new incoming connections.

public bool RefuseNewConnections { get; set; }

Property Value

bool

RootPath

The root path to use for RPCs and replication. Instead of an absolute path, a relative path will be used to find the node upon which the RPC should be executed.

This effectively allows to have different branches of the scene tree to be managed by different MultiplayerAPI, allowing for example to run both client and server in the same scene.

public NodePath RootPath { get; set; }

Property Value

NodePath

ServerRelay

Enable or disable the server feature that notifies clients of other peers' connection/disconnection, and relays messages between them. When this option is false, clients won't be automatically notified of other peers and won't be able to send them packets through the server.

Note: Changing this option while other peers are connected may lead to unexpected behaviors.

Note: Support for this feature may depend on the current MultiplayerPeer configuration. See IsServerRelaySupported().

public bool ServerRelay { get; set; }

Property Value

bool

Methods

Clear()

Clears the current SceneMultiplayer network state (you shouldn't call this unless you know what you are doing).

public void Clear()

CompleteAuth(int)

Mark the authentication step as completed for the remote peer identified by id. The PeerConnected signal will be emitted for this peer once the remote side also completes the authentication. No further authentication messages are expected to be received from this peer.

If a peer disconnects before completing authentication, either due to a network issue, the AuthTimeout expiring, or manually calling DisconnectPeer(int), the PeerAuthenticationFailed signal will be emitted instead of PeerDisconnected.

public Error CompleteAuth(int id)

Parameters

id int

Returns

Error

DisconnectPeer(int)

Disconnects the peer identified by id, removing it from the list of connected peers, and closing the underlying connection with it.

public void DisconnectPeer(int id)

Parameters

id int

GetAuthenticatingPeers()

Returns the IDs of the peers currently trying to authenticate with this MultiplayerApi.

public int[] GetAuthenticatingPeers()

Returns

int[]

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_name

Name of the method to check for.

Returns

bool

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_name

Name of the signal to check for.

Returns

bool

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_name

Name of the method to invoke.

args NativeVariantPtrArgs

Arguments to use with the invoked method.

ret godot_variant

Value returned by the invoked method.

Returns

bool

SendAuth(int, byte[])

Sends the specified data to the remote peer identified by id as part of an authentication message. This can be used to authenticate peers, and control when PeerConnected is emitted (and the remote peer accepted as one of the connected peers).

public Error SendAuth(int id, byte[] data)

Parameters

id int
data byte[]

Returns

Error

SendBytes(byte[], int, TransferModeEnum, int)

Sends the given raw bytes to a specific peer identified by id (see SetTargetPeer(int)). Default ID is 0, i.e. broadcast to all peers.

public Error SendBytes(byte[] bytes, int id = 0, MultiplayerPeer.TransferModeEnum mode = TransferModeEnum.Reliable, int channel = 0)

Parameters

bytes byte[]
id int
mode MultiplayerPeer.TransferModeEnum
channel int

Returns

Error

Events

PeerAuthenticating

Emitted when this MultiplayerAPI's MultiplayerPeer connects to a new peer and a valid AuthCallback is set. In this case, the PeerConnected will not be emitted until CompleteAuth(int) is called with given peer id. While in this state, the peer will not be included in the list returned by GetPeers() (but in the one returned by GetAuthenticatingPeers()), and only authentication data will be sent or received. See SendAuth(int, byte[]) for sending authentication data.

public event SceneMultiplayer.PeerAuthenticatingEventHandler PeerAuthenticating

Event Type

SceneMultiplayer.PeerAuthenticatingEventHandler

PeerAuthenticationFailed

Emitted when this MultiplayerAPI's MultiplayerPeer disconnects from a peer for which authentication had not yet completed. See PeerAuthenticating.

public event SceneMultiplayer.PeerAuthenticationFailedEventHandler PeerAuthenticationFailed

Event Type

SceneMultiplayer.PeerAuthenticationFailedEventHandler

PeerPacket

Emitted when this MultiplayerAPI's MultiplayerPeer receives a packet with custom data (see SendBytes(byte[], int, TransferModeEnum, int)). ID is the peer ID of the peer that sent the packet.

public event SceneMultiplayer.PeerPacketEventHandler PeerPacket

Event Type

SceneMultiplayer.PeerPacketEventHandler