:github_url: hide .. Generated automatically by doc/tools/make_rst.py in Godot's source tree. .. DO NOT EDIT THIS FILE, but the MultiplayerReplicator.xml source instead. .. The source is found in doc/classes or modules//doc_classes. .. _class_MultiplayerReplicator: MultiplayerReplicator ===================== **Inherits:** :ref:`Object` Methods ------- +-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Error` | :ref:`decode_state` **(** :ref:`int` scene_id, :ref:`Object` object, :ref:`PackedByteArray` data, :ref:`bool` initial=true **)** | +-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Error` | :ref:`despawn` **(** :ref:`int` scene_id, :ref:`Object` object, :ref:`int` peer_id=0 **)** | +-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`PackedByteArray` | :ref:`encode_state` **(** :ref:`int` scene_id, :ref:`Object` object, :ref:`bool` initial=true **)** | +-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Error` | :ref:`send_despawn` **(** :ref:`int` peer_id, :ref:`int` scene_id, :ref:`Variant` data=null, :ref:`NodePath` path=NodePath("") **)** | +-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Error` | :ref:`send_spawn` **(** :ref:`int` peer_id, :ref:`int` scene_id, :ref:`Variant` data=null, :ref:`NodePath` path=NodePath("") **)** | +-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Error` | :ref:`send_sync` **(** :ref:`int` peer_id, :ref:`int` scene_id, :ref:`PackedByteArray` data, :ref:`TransferMode` transfer_mode=2, :ref:`int` channel=0 **)** | +-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Error` | :ref:`spawn` **(** :ref:`int` scene_id, :ref:`Object` object, :ref:`int` peer_id=0 **)** | +-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Error` | :ref:`spawn_config` **(** :ref:`int` scene_id, :ref:`ReplicationMode` spawn_mode, :ref:`StringName[]` properties=[], :ref:`Callable` custom_send, :ref:`Callable` custom_receive **)** | +-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Error` | :ref:`sync_all` **(** :ref:`int` scene_id, :ref:`int` peer_id=0 **)** | +-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Error` | :ref:`sync_config` **(** :ref:`int` scene_id, :ref:`int` interval, :ref:`StringName[]` properties=[], :ref:`Callable` custom_send, :ref:`Callable` custom_receive **)** | +-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`track` **(** :ref:`int` scene_id, :ref:`Object` object **)** | +-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`untrack` **(** :ref:`int` scene_id, :ref:`Object` object **)** | +-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ Signals ------- .. _class_MultiplayerReplicator_signal_despawn_requested: - **despawn_requested** **(** :ref:`int` id, :ref:`int` scene_id, :ref:`Node` parent, :ref:`String` name, :ref:`PackedByteArray` data **)** Emitted when a network despawn request has been received from a client, or for a :ref:`PackedScene` that has been configured as :ref:`REPLICATION_MODE_CUSTOM`. ---- .. _class_MultiplayerReplicator_signal_despawned: - **despawned** **(** :ref:`int` scene_id, :ref:`Node` node **)** Emitted on a client before deleting a local Node upon receiving a despawn request from the server. ---- .. _class_MultiplayerReplicator_signal_replicated_instance_added: - **replicated_instance_added** **(** :ref:`int` scene_id, :ref:`Node` node **)** Emitted when an instance of a :ref:`PackedScene` that has been configured for networking enters the :ref:`SceneTree`. See :ref:`spawn_config`. ---- .. _class_MultiplayerReplicator_signal_replicated_instance_removed: - **replicated_instance_removed** **(** :ref:`int` scene_id, :ref:`Node` node **)** Emitted when an instance of a :ref:`PackedScene` that has been configured for networking leaves the :ref:`SceneTree`. See :ref:`spawn_config`. ---- .. _class_MultiplayerReplicator_signal_spawn_requested: - **spawn_requested** **(** :ref:`int` id, :ref:`int` scene_id, :ref:`Node` parent, :ref:`String` name, :ref:`PackedByteArray` data **)** Emitted when a network spawn request has been received from a client, or for a :ref:`PackedScene` that has been configured as :ref:`REPLICATION_MODE_CUSTOM`. ---- .. _class_MultiplayerReplicator_signal_spawned: - **spawned** **(** :ref:`int` scene_id, :ref:`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_MultiplayerReplicator_ReplicationMode: .. _class_MultiplayerReplicator_constant_REPLICATION_MODE_NONE: .. _class_MultiplayerReplicator_constant_REPLICATION_MODE_SERVER: .. _class_MultiplayerReplicator_constant_REPLICATION_MODE_CUSTOM: enum **ReplicationMode**: - **REPLICATION_MODE_NONE** = **0** --- Used with :ref:`spawn_config` to identify a :ref:`PackedScene` that should not be replicated. - **REPLICATION_MODE_SERVER** = **1** --- Used with :ref:`spawn_config` to identify a :ref:`PackedScene` that should be automatically replicated from server to clients. - **REPLICATION_MODE_CUSTOM** = **2** --- Used with :ref:`spawn_config` to identify a :ref:`PackedScene` that can be manually replicated among peers. Method Descriptions ------------------- .. _class_MultiplayerReplicator_method_decode_state: - :ref:`Error` **decode_state** **(** :ref:`int` scene_id, :ref:`Object` object, :ref:`PackedByteArray` data, :ref:`bool` initial=true **)** 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 :ref:`REPLICATION_MODE_SERVER`. See :ref:`spawn_config`. Tip: You may find this function useful in servers when parsing spawn requests from clients, or when implementing your own logic with :ref:`REPLICATION_MODE_CUSTOM`. ---- .. _class_MultiplayerReplicator_method_despawn: - :ref:`Error` **despawn** **(** :ref:`int` scene_id, :ref:`Object` object, :ref:`int` peer_id=0 **)** 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 :ref:`spawn_config`. See :ref:`send_despawn` for the default behavior. ---- .. _class_MultiplayerReplicator_method_encode_state: - :ref:`PackedByteArray` **encode_state** **(** :ref:`int` scene_id, :ref:`Object` object, :ref:`bool` initial=true **)** Encode the given ``object`` using the configuration associated with the provided ``scene_id``. This function is called automatically when the server spawns scenes with :ref:`REPLICATION_MODE_SERVER`. See :ref:`spawn_config`. Tip: You may find this function useful when requesting spawns from clients to server, or when implementing your own logic with :ref:`REPLICATION_MODE_CUSTOM`. ---- .. _class_MultiplayerReplicator_method_send_despawn: - :ref:`Error` **send_despawn** **(** :ref:`int` peer_id, :ref:`int` scene_id, :ref:`Variant` data=null, :ref:`NodePath` path=NodePath("") **)** Sends a despawn request for the scene identified by ``scene_id`` to the given ``peer_id`` (see :ref:`MultiplayerPeer.set_target_peer`). If the scene is configured as :ref:`REPLICATION_MODE_SERVER` (see :ref:`spawn_config`) and the request is sent by the server (see :ref:`MultiplayerAPI.is_server`), the receiving peer(s) will automatically queue for deletion the node at ``path`` and emit the signal :ref:`despawned`. In all other cases no deletion happens, and the signal :ref:`despawn_requested` is emitted instead. ---- .. _class_MultiplayerReplicator_method_send_spawn: - :ref:`Error` **send_spawn** **(** :ref:`int` peer_id, :ref:`int` scene_id, :ref:`Variant` data=null, :ref:`NodePath` path=NodePath("") **)** Sends a spawn request for the scene identified by ``scene_id`` to the given ``peer_id`` (see :ref:`MultiplayerPeer.set_target_peer`). If the scene is configured as :ref:`REPLICATION_MODE_SERVER` (see :ref:`spawn_config`) and the request is sent by the server (see :ref:`MultiplayerAPI.is_server`), the receiving peer(s) will automatically instantiate that scene, add it to the :ref:`SceneTree` at the given ``path`` and emit the signal :ref:`spawned`. In all other cases no instantiation happens, and the signal :ref:`spawn_requested` is emitted instead. ---- .. _class_MultiplayerReplicator_method_send_sync: - :ref:`Error` **send_sync** **(** :ref:`int` peer_id, :ref:`int` scene_id, :ref:`PackedByteArray` data, :ref:`TransferMode` transfer_mode=2, :ref:`int` channel=0 **)** Sends a sync request for the instances of the scene identified by ``scene_id`` to the given ``peer_id`` (see :ref:`MultiplayerPeer.set_target_peer`). This function can only be called manually when overriding the send and receive sync functions (see :ref:`sync_config`). ---- .. _class_MultiplayerReplicator_method_spawn: - :ref:`Error` **spawn** **(** :ref:`int` scene_id, :ref:`Object` object, :ref:`int` peer_id=0 **)** 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 :ref:`spawn_config`. See :ref:`send_spawn` for the default behavior. ---- .. _class_MultiplayerReplicator_method_spawn_config: - :ref:`Error` **spawn_config** **(** :ref:`int` scene_id, :ref:`ReplicationMode` spawn_mode, :ref:`StringName[]` properties=[], :ref:`Callable` custom_send, :ref:`Callable` custom_receive **)** Configures the MultiplayerReplicator to track instances of the :ref:`PackedScene` identified by ``scene_id`` (see :ref:`ResourceLoader.get_resource_uid`) for the purpose of network replication. When ``mode`` is :ref:`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. ---- .. _class_MultiplayerReplicator_method_sync_all: - :ref:`Error` **sync_all** **(** :ref:`int` scene_id, :ref:`int` peer_id=0 **)** 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 :ref:`sync_config`. **Note:** The default implementation only allow syncing from server to clients. ---- .. _class_MultiplayerReplicator_method_sync_config: - :ref:`Error` **sync_config** **(** :ref:`int` scene_id, :ref:`int` interval, :ref:`StringName[]` properties=[], :ref:`Callable` custom_send, :ref:`Callable` custom_receive **)** Configures the MultiplayerReplicator to sync instances of the :ref:`PackedScene` identified by ``scene_id`` (see :ref:`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). ---- .. _class_MultiplayerReplicator_method_track: - void **track** **(** :ref:`int` scene_id, :ref:`Object` object **)** 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 :ref:`sync_config`). Tracking and untracking is automatic in :ref:`REPLICATION_MODE_SERVER`. ---- .. _class_MultiplayerReplicator_method_untrack: - void **untrack** **(** :ref:`int` scene_id, :ref:`Object` object **)** Untrack the given ``object``. This object will no longer be passed to your custom sync callables (see :ref:`sync_config`). Tracking and untracking is automatic in :ref:`REPLICATION_MODE_SERVER`. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)` .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)` .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)` .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)` .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)` .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`