MultiplayerReplicator

Inherits: Object

Methods

Error

decode_state ( int scene_id, Object object, PackedByteArray data, bool initial=true )

Error

despawn ( int scene_id, Object object, int peer_id=0 )

PackedByteArray

encode_state ( int scene_id, Object object, bool initial=true )

Error

send_despawn ( int peer_id, int scene_id, Variant data=null, NodePath path=NodePath("") )

Error

send_spawn ( int peer_id, int scene_id, Variant data=null, NodePath path=NodePath("") )

Error

send_sync ( int peer_id, int scene_id, PackedByteArray data, TransferMode transfer_mode=2, int channel=0 )

Error

spawn ( int scene_id, Object object, int peer_id=0 )

Error

spawn_config ( int scene_id, ReplicationMode spawn_mode, StringName[] properties=[], Callable custom_send, Callable custom_receive )

Error

sync_all ( int scene_id, int peer_id=0 )

Error

sync_config ( int scene_id, int interval, StringName[] properties=[], Callable custom_send, Callable custom_receive )

void

track ( int scene_id, Object object )

void

untrack ( int scene_id, Object object )

Signals

Emitted when a network despawn request has been received from a client, or for a PackedScene that has been configured as REPLICATION_MODE_CUSTOM.


  • despawned ( int scene_id, Node node )

Emitted on a client before deleting a local Node upon receiving a despawn request from the server.


  • replicated_instance_added ( int scene_id, Node node )

Emitted when an instance of a PackedScene that has been configured for networking enters the SceneTree. See spawn_config.


  • replicated_instance_removed ( int scene_id, Node node )

Emitted when an instance of a PackedScene that has been configured for networking leaves the SceneTree. See spawn_config.


Emitted when a network spawn request has been received from a client, or for a PackedScene that has been configured as REPLICATION_MODE_CUSTOM.


  • spawned ( int scene_id, Node node )

Emitted on a client after a new Node is instantiated locally and added to the SceneTree upon receiving a spawn request from the server.

Enumerations

enum ReplicationMode:

  • REPLICATION_MODE_NONE = 0 --- Used with spawn_config to identify a PackedScene that should not be replicated.

  • REPLICATION_MODE_SERVER = 1 --- Used with spawn_config to identify a PackedScene that should be automatically replicated from server to clients.

  • REPLICATION_MODE_CUSTOM = 2 --- Used with spawn_config to identify a PackedScene that can be manually replicated among peers.

Method Descriptions

Decode the given data representing a spawnable state into object using the configuration associated with the provided scene_id. This function is called automatically when a client receives a server spawn for a scene with REPLICATION_MODE_SERVER. See spawn_config.

Tip: You may find this function useful in servers when parsing spawn requests from clients, or when implementing your own logic with REPLICATION_MODE_CUSTOM.


Request a despawn for the scene identified by scene_id to the given peer_id. This will either trigger the default behaviour, or invoke the custom spawn/despawn callables specified in spawn_config. See send_despawn for the default behavior.


Encode the given object using the configuration associated with the provided scene_id. This function is called automatically when the server spawns scenes with REPLICATION_MODE_SERVER. See spawn_config.

Tip: You may find this function useful when requesting spawns from clients to server, or when implementing your own logic with REPLICATION_MODE_CUSTOM.


Sends a despawn request for the scene identified by scene_id to the given peer_id (see MultiplayerPeer.set_target_peer). If the scene is configured as REPLICATION_MODE_SERVER (see spawn_config) and the request is sent by the server (see MultiplayerAPI.is_server), the receiving peer(s) will automatically queue for deletion the node at path and emit the signal despawned. In all other cases no deletion happens, and the signal despawn_requested is emitted instead.


Sends a spawn request for the scene identified by scene_id to the given peer_id (see MultiplayerPeer.set_target_peer). If the scene is configured as REPLICATION_MODE_SERVER (see spawn_config) and the request is sent by the server (see MultiplayerAPI.is_server), the receiving peer(s) will automatically instantiate that scene, add it to the SceneTree at the given path and emit the signal spawned. In all other cases no instantiation happens, and the signal spawn_requested is emitted instead.


Sends a sync request for the instances of the scene identified by scene_id to the given peer_id (see MultiplayerPeer.set_target_peer). This function can only be called manually when overriding the send and receive sync functions (see sync_config).


Request a spawn for the scene identified by scene_id to the given peer_id. This will either trigger the default behaviour, or invoke the custom spawn/despawn callables specified in spawn_config. See send_spawn for the default behavior.


Configures the MultiplayerReplicator to track instances of the PackedScene identified by scene_id (see ResourceLoader.get_resource_uid) for the purpose of network replication. When mode is REPLICATION_MODE_SERVER, the specified properties will also be replicated to clients during the initial spawn. You can optionally specify a custom_send and a custom_receive to override the default behaviour and customize the spawn/despawn proecess.

Tip: You can use a custom property in the scene main script to return a customly optimized state representation.


Manually request a sync for all the instances of the scene identified by scene_id. This function will trigger the default sync behaviour, or call your send custom send callable if specified in sync_config.

Note: The default implementation only allow syncing from server to clients.


Configures the MultiplayerReplicator to sync instances of the PackedScene identified by scene_id (see ResourceLoader.get_resource_uid) for the purpose of network replication at the desired interval (in milliseconds). The specified properties will be part of the state sync. You can optionally specify a custom_send and a custom_receive to override the default behaviour and customize the syncronization proecess.

Tip: You can use a custom property in the scene main script to return a customly optimized state representation (having a single property that returns a PackedByteArray is higly recommended when dealing with many instances).


Track the given object as an instance of the scene identified by scene_id. This object will be passed to your custom sync callables (see sync_config). Tracking and untracking is automatic in REPLICATION_MODE_SERVER.


  • void untrack ( int scene_id, Object object )

Untrack the given object. This object will no longer be passed to your custom sync callables (see sync_config). Tracking and untracking is automatic in REPLICATION_MODE_SERVER.