SceneMultiplayer
The high-level network context for an Entity hierarchy.
Handles RPC and configured replication relative to a network root. RootPath defines relative-path space; matching code/configuration must address corresponding entities on peers.
Do not enable AllowObjectDecoding just to accept arbitrary external data. Peer connectivity, user authentication, gameplay rights, sequence and request bounds are separate concerns. Defer tree API-table mutation out of network callbacks to a suitable main-thread phase.
Declarations checked against C# SDK 1.0.0. Expand a name to see declarations and documentation.
Constructors1
SceneMultiplayerConstructor
public SceneMultiplayer();Properties8
AllowObjectDecodingProperty
public bool AllowObjectDecoding { get; set; }Object-decoding permission. Keep false for a simple external protocol; this is not universal safe network-identity serialization.
AuthCallbackProperty
public Callable AuthCallback { get; set; }The callback to execute when receiving authentication data sent via SceneMultiplayer.SendAuth. If the Callable is empty (default), peers will be automatically accepted as soon as they connect.
AuthTimeoutProperty
public double AuthTimeout { get; set; }If set to a value greater than 0.0, the maximum duration in seconds peers can stay in the authenticating state, after which the authentication will automatically fail. See the SceneMultiplayer.PeerAuthenticating and SceneMultiplayer.PeerAuthenticationFailed signals.
MaxDeltaPacketSizeProperty
public int MaxDeltaPacketSize { get; set; }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.
MaxSyncPacketSizeProperty
public int MaxSyncPacketSize { get; set; }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.
RefuseNewConnectionsProperty
public bool RefuseNewConnections { get; set; }If true, the MultiplayerAPI's MultiplayerApi.MultiplayerPeer refuses new incoming connections.
RootPathProperty
public EntityPath RootPath { get; set; }Network root for relative Entity paths. Corresponding RPC objects must match relative to each participant's root.
ServerRelayProperty
public bool ServerRelay { get; set; }Controls relay between clients through the server. The guide lobby sets false for client/server-only exchange. The checked build exhibited a native failure with true during simultaneous client disconnects; this example does not establish correct operation of that mode.
Methods24
Clearvoid
public void Clear();Clears the current SceneMultiplayer network state (you shouldn't call this unless you know what you are doing).
CompleteAuthError
public Error CompleteAuth(int id);Mark the authentication step as completed for the remote peer identified by id. The MultiplayerApi.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 SceneMultiplayer.AuthTimeout expiring, or manually calling SceneMultiplayer.DisconnectPeer, the SceneMultiplayer.PeerAuthenticationFailed signal will be emitted instead of MultiplayerApi.PeerDisconnected.
| Name | Type | Default |
|---|---|---|
id | int | — |
ErrorDisconnectPeervoid
public void DisconnectPeer(int id);Disconnects the peer identified by id, removing it from the list of connected peers, and closing the underlying connection with it.
| Name | Type | Default |
|---|---|---|
id | int | — |
GetAuthCallbackCallable
public Callable GetAuthCallback();CallableGetAuthTimeoutdouble
public double GetAuthTimeout();doubleGetAuthenticatingPeersint[]
public int[] GetAuthenticatingPeers();Returns the IDs of the peers currently trying to authenticate with this MultiplayerApi.
int[]GetMaxDeltaPacketSizeint
public int GetMaxDeltaPacketSize();intGetMaxSyncPacketSizeint
public int GetMaxSyncPacketSize();intGetRootPathEntityPath
public EntityPath GetRootPath();EntityPathIsObjectDecodingAllowedbool
public bool IsObjectDecodingAllowed();boolIsRefusingNewConnectionsbool
public bool IsRefusingNewConnections();boolIsServerRelayEnabledbool
public bool IsServerRelayEnabled();boolSendAuth2 overloads
public Error SendAuth(int id, byte[] data);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 MultiplayerApi.PeerConnected is emitted (and the remote peer accepted as one of the connected peers).
| Name | Type | Default |
|---|---|---|
id | int | — |
data | byte[] | — |
Errorpublic Error SendAuth(int id, ReadOnlySpan<byte> data);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 MultiplayerApi.PeerConnected is emitted (and the remote peer accepted as one of the connected peers).
| Name | Type | Default |
|---|---|---|
id | int | — |
data | ReadOnlySpan<byte> | — |
ErrorSendBytes2 overloads
public Error SendBytes(byte[] bytes, int id = 0, MultiplayerPeer.TransferModeEnum mode = MultiplayerPeer.TransferModeEnum.Reliable, int channel = 0);Sends the given raw bytes to a specific peer identified by id (see MultiplayerPeer.SetTargetPeer). Default ID is 0, i.e. broadcast to all peers.
| Name | Type | Default |
|---|---|---|
bytes | byte[] | — |
id | int | 0 |
mode | MultiplayerPeer.TransferModeEnum | MultiplayerPeer.TransferModeEnum.Reliable |
channel | int | 0 |
Errorpublic Error SendBytes(ReadOnlySpan<byte> bytes, int id, MultiplayerPeer.TransferModeEnum mode, int channel);Sends the given raw bytes to a specific peer identified by id (see MultiplayerPeer.SetTargetPeer). Default ID is 0, i.e. broadcast to all peers.
| Name | Type | Default |
|---|---|---|
bytes | ReadOnlySpan<byte> | — |
id | int | — |
mode | MultiplayerPeer.TransferModeEnum | — |
channel | int | — |
ErrorSetAllowObjectDecodingvoid
public void SetAllowObjectDecoding(bool enable);| Name | Type | Default |
|---|---|---|
enable | bool | — |
SetAuthCallbackvoid
public void SetAuthCallback(Callable callback);| Name | Type | Default |
|---|---|---|
callback | Callable | — |
SetAuthTimeoutvoid
public void SetAuthTimeout(double timeout);| Name | Type | Default |
|---|---|---|
timeout | double | — |
SetMaxDeltaPacketSizevoid
public void SetMaxDeltaPacketSize(int size);| Name | Type | Default |
|---|---|---|
size | int | — |
SetMaxSyncPacketSizevoid
public void SetMaxSyncPacketSize(int size);| Name | Type | Default |
|---|---|---|
size | int | — |
SetRefuseNewConnectionsvoid
public void SetRefuseNewConnections(bool refuse);| Name | Type | Default |
|---|---|---|
refuse | bool | — |
SetRootPathvoid
public void SetRootPath(EntityPath path);| Name | Type | Default |
|---|---|---|
path | EntityPath | — |
SetServerRelayEnabledvoid
public void SetServerRelayEnabled(bool enabled);| Name | Type | Default |
|---|---|---|
enabled | bool | — |
Signals and events3
PeerAuthenticatingEvent
public event SceneMultiplayer.PeerAuthenticatingEventHandler PeerAuthenticating;Emitted when this MultiplayerAPI's MultiplayerApi.MultiplayerPeer connects to a new peer and a valid SceneMultiplayer.AuthCallback is set. In this case, the MultiplayerApi.PeerConnected will not be emitted until SceneMultiplayer.CompleteAuth is called with given peer id. While in this state, the peer will not be included in the list returned by MultiplayerApi.GetPeers (but in the one returned by SceneMultiplayer.GetAuthenticatingPeers), and only authentication data will be sent or received. See SceneMultiplayer.SendAuth for sending authentication data.
| Name | Type | Default |
|---|---|---|
id | long | — |
PeerAuthenticationFailedEvent
public event SceneMultiplayer.PeerAuthenticationFailedEventHandler PeerAuthenticationFailed;Emitted when this MultiplayerAPI's MultiplayerApi.MultiplayerPeer disconnects from a peer for which authentication had not yet completed. See SceneMultiplayer.PeerAuthenticating.
| Name | Type | Default |
|---|---|---|
id | long | — |
PeerPacketEvent
public event SceneMultiplayer.PeerPacketEventHandler PeerPacket;Emitted when this MultiplayerAPI's MultiplayerApi.MultiplayerPeer receives a packet with custom data (see SceneMultiplayer.SendBytes). ID is the peer ID of the peer that sent the packet.
| Name | Type | Default |
|---|---|---|
id | long | — |
packet | byte[] | — |