123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225 |
- :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/<name>/doc_classes.
- .. _class_MultiplayerReplicator:
- MultiplayerReplicator
- =====================
- **Inherits:** :ref:`Object<class_Object>`
- Methods
- -------
- +-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`decode_state<class_MultiplayerReplicator_method_decode_state>` **(** :ref:`int<class_int>` scene_id, :ref:`Object<class_Object>` object, :ref:`PackedByteArray<class_PackedByteArray>` data, :ref:`bool<class_bool>` initial=true **)** |
- +-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`despawn<class_MultiplayerReplicator_method_despawn>` **(** :ref:`int<class_int>` scene_id, :ref:`Object<class_Object>` object, :ref:`int<class_int>` peer_id=0 **)** |
- +-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`PackedByteArray<class_PackedByteArray>` | :ref:`encode_state<class_MultiplayerReplicator_method_encode_state>` **(** :ref:`int<class_int>` scene_id, :ref:`Object<class_Object>` object, :ref:`bool<class_bool>` initial=true **)** |
- +-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`send_despawn<class_MultiplayerReplicator_method_send_despawn>` **(** :ref:`int<class_int>` peer_id, :ref:`int<class_int>` scene_id, :ref:`Variant<class_Variant>` data=null, :ref:`NodePath<class_NodePath>` path=NodePath("") **)** |
- +-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`send_spawn<class_MultiplayerReplicator_method_send_spawn>` **(** :ref:`int<class_int>` peer_id, :ref:`int<class_int>` scene_id, :ref:`Variant<class_Variant>` data=null, :ref:`NodePath<class_NodePath>` path=NodePath("") **)** |
- +-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`send_sync<class_MultiplayerReplicator_method_send_sync>` **(** :ref:`int<class_int>` peer_id, :ref:`int<class_int>` scene_id, :ref:`PackedByteArray<class_PackedByteArray>` data, :ref:`TransferMode<enum_@GlobalScope_TransferMode>` transfer_mode=2, :ref:`int<class_int>` channel=0 **)** |
- +-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`spawn<class_MultiplayerReplicator_method_spawn>` **(** :ref:`int<class_int>` scene_id, :ref:`Object<class_Object>` object, :ref:`int<class_int>` peer_id=0 **)** |
- +-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`spawn_config<class_MultiplayerReplicator_method_spawn_config>` **(** :ref:`int<class_int>` scene_id, :ref:`ReplicationMode<enum_MultiplayerReplicator_ReplicationMode>` spawn_mode, :ref:`StringName[]<class_StringName>` properties=[], :ref:`Callable<class_Callable>` custom_send, :ref:`Callable<class_Callable>` custom_receive **)** |
- +-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`sync_all<class_MultiplayerReplicator_method_sync_all>` **(** :ref:`int<class_int>` scene_id, :ref:`int<class_int>` peer_id=0 **)** |
- +-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`sync_config<class_MultiplayerReplicator_method_sync_config>` **(** :ref:`int<class_int>` scene_id, :ref:`int<class_int>` interval, :ref:`StringName[]<class_StringName>` properties=[], :ref:`Callable<class_Callable>` custom_send, :ref:`Callable<class_Callable>` custom_receive **)** |
- +-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | void | :ref:`track<class_MultiplayerReplicator_method_track>` **(** :ref:`int<class_int>` scene_id, :ref:`Object<class_Object>` object **)** |
- +-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | void | :ref:`untrack<class_MultiplayerReplicator_method_untrack>` **(** :ref:`int<class_int>` scene_id, :ref:`Object<class_Object>` object **)** |
- +-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- Signals
- -------
- .. _class_MultiplayerReplicator_signal_despawn_requested:
- - **despawn_requested** **(** :ref:`int<class_int>` id, :ref:`int<class_int>` scene_id, :ref:`Node<class_Node>` parent, :ref:`String<class_String>` name, :ref:`PackedByteArray<class_PackedByteArray>` data **)**
- Emitted when a network despawn request has been received from a client, or for a :ref:`PackedScene<class_PackedScene>` that has been configured as :ref:`REPLICATION_MODE_CUSTOM<class_MultiplayerReplicator_constant_REPLICATION_MODE_CUSTOM>`.
- ----
- .. _class_MultiplayerReplicator_signal_despawned:
- - **despawned** **(** :ref:`int<class_int>` scene_id, :ref:`Node<class_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<class_int>` scene_id, :ref:`Node<class_Node>` node **)**
- Emitted when an instance of a :ref:`PackedScene<class_PackedScene>` that has been configured for networking enters the :ref:`SceneTree<class_SceneTree>`. See :ref:`spawn_config<class_MultiplayerReplicator_method_spawn_config>`.
- ----
- .. _class_MultiplayerReplicator_signal_replicated_instance_removed:
- - **replicated_instance_removed** **(** :ref:`int<class_int>` scene_id, :ref:`Node<class_Node>` node **)**
- Emitted when an instance of a :ref:`PackedScene<class_PackedScene>` that has been configured for networking leaves the :ref:`SceneTree<class_SceneTree>`. See :ref:`spawn_config<class_MultiplayerReplicator_method_spawn_config>`.
- ----
- .. _class_MultiplayerReplicator_signal_spawn_requested:
- - **spawn_requested** **(** :ref:`int<class_int>` id, :ref:`int<class_int>` scene_id, :ref:`Node<class_Node>` parent, :ref:`String<class_String>` name, :ref:`PackedByteArray<class_PackedByteArray>` data **)**
- Emitted when a network spawn request has been received from a client, or for a :ref:`PackedScene<class_PackedScene>` that has been configured as :ref:`REPLICATION_MODE_CUSTOM<class_MultiplayerReplicator_constant_REPLICATION_MODE_CUSTOM>`.
- ----
- .. _class_MultiplayerReplicator_signal_spawned:
- - **spawned** **(** :ref:`int<class_int>` scene_id, :ref:`Node<class_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<class_MultiplayerReplicator_method_spawn_config>` to identify a :ref:`PackedScene<class_PackedScene>` that should not be replicated.
- - **REPLICATION_MODE_SERVER** = **1** --- Used with :ref:`spawn_config<class_MultiplayerReplicator_method_spawn_config>` to identify a :ref:`PackedScene<class_PackedScene>` that should be automatically replicated from server to clients.
- - **REPLICATION_MODE_CUSTOM** = **2** --- Used with :ref:`spawn_config<class_MultiplayerReplicator_method_spawn_config>` to identify a :ref:`PackedScene<class_PackedScene>` that can be manually replicated among peers.
- Method Descriptions
- -------------------
- .. _class_MultiplayerReplicator_method_decode_state:
- - :ref:`Error<enum_@GlobalScope_Error>` **decode_state** **(** :ref:`int<class_int>` scene_id, :ref:`Object<class_Object>` object, :ref:`PackedByteArray<class_PackedByteArray>` data, :ref:`bool<class_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<class_MultiplayerReplicator_constant_REPLICATION_MODE_SERVER>`. See :ref:`spawn_config<class_MultiplayerReplicator_method_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_constant_REPLICATION_MODE_CUSTOM>`.
- ----
- .. _class_MultiplayerReplicator_method_despawn:
- - :ref:`Error<enum_@GlobalScope_Error>` **despawn** **(** :ref:`int<class_int>` scene_id, :ref:`Object<class_Object>` object, :ref:`int<class_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<class_MultiplayerReplicator_method_spawn_config>`. See :ref:`send_despawn<class_MultiplayerReplicator_method_send_despawn>` for the default behavior.
- ----
- .. _class_MultiplayerReplicator_method_encode_state:
- - :ref:`PackedByteArray<class_PackedByteArray>` **encode_state** **(** :ref:`int<class_int>` scene_id, :ref:`Object<class_Object>` object, :ref:`bool<class_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<class_MultiplayerReplicator_constant_REPLICATION_MODE_SERVER>`. See :ref:`spawn_config<class_MultiplayerReplicator_method_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_constant_REPLICATION_MODE_CUSTOM>`.
- ----
- .. _class_MultiplayerReplicator_method_send_despawn:
- - :ref:`Error<enum_@GlobalScope_Error>` **send_despawn** **(** :ref:`int<class_int>` peer_id, :ref:`int<class_int>` scene_id, :ref:`Variant<class_Variant>` data=null, :ref:`NodePath<class_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<class_MultiplayerPeer_method_set_target_peer>`). If the scene is configured as :ref:`REPLICATION_MODE_SERVER<class_MultiplayerReplicator_constant_REPLICATION_MODE_SERVER>` (see :ref:`spawn_config<class_MultiplayerReplicator_method_spawn_config>`) and the request is sent by the server (see :ref:`MultiplayerAPI.is_server<class_MultiplayerAPI_method_is_server>`), the receiving peer(s) will automatically queue for deletion the node at ``path`` and emit the signal :ref:`despawned<class_MultiplayerReplicator_signal_despawned>`. In all other cases no deletion happens, and the signal :ref:`despawn_requested<class_MultiplayerReplicator_signal_despawn_requested>` is emitted instead.
- ----
- .. _class_MultiplayerReplicator_method_send_spawn:
- - :ref:`Error<enum_@GlobalScope_Error>` **send_spawn** **(** :ref:`int<class_int>` peer_id, :ref:`int<class_int>` scene_id, :ref:`Variant<class_Variant>` data=null, :ref:`NodePath<class_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<class_MultiplayerPeer_method_set_target_peer>`). If the scene is configured as :ref:`REPLICATION_MODE_SERVER<class_MultiplayerReplicator_constant_REPLICATION_MODE_SERVER>` (see :ref:`spawn_config<class_MultiplayerReplicator_method_spawn_config>`) and the request is sent by the server (see :ref:`MultiplayerAPI.is_server<class_MultiplayerAPI_method_is_server>`), the receiving peer(s) will automatically instantiate that scene, add it to the :ref:`SceneTree<class_SceneTree>` at the given ``path`` and emit the signal :ref:`spawned<class_MultiplayerReplicator_signal_spawned>`. In all other cases no instantiation happens, and the signal :ref:`spawn_requested<class_MultiplayerReplicator_signal_spawn_requested>` is emitted instead.
- ----
- .. _class_MultiplayerReplicator_method_send_sync:
- - :ref:`Error<enum_@GlobalScope_Error>` **send_sync** **(** :ref:`int<class_int>` peer_id, :ref:`int<class_int>` scene_id, :ref:`PackedByteArray<class_PackedByteArray>` data, :ref:`TransferMode<enum_@GlobalScope_TransferMode>` transfer_mode=2, :ref:`int<class_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<class_MultiplayerPeer_method_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_sync_config>`).
- ----
- .. _class_MultiplayerReplicator_method_spawn:
- - :ref:`Error<enum_@GlobalScope_Error>` **spawn** **(** :ref:`int<class_int>` scene_id, :ref:`Object<class_Object>` object, :ref:`int<class_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<class_MultiplayerReplicator_method_spawn_config>`. See :ref:`send_spawn<class_MultiplayerReplicator_method_send_spawn>` for the default behavior.
- ----
- .. _class_MultiplayerReplicator_method_spawn_config:
- - :ref:`Error<enum_@GlobalScope_Error>` **spawn_config** **(** :ref:`int<class_int>` scene_id, :ref:`ReplicationMode<enum_MultiplayerReplicator_ReplicationMode>` spawn_mode, :ref:`StringName[]<class_StringName>` properties=[], :ref:`Callable<class_Callable>` custom_send, :ref:`Callable<class_Callable>` custom_receive **)**
- Configures the MultiplayerReplicator to track instances of the :ref:`PackedScene<class_PackedScene>` identified by ``scene_id`` (see :ref:`ResourceLoader.get_resource_uid<class_ResourceLoader_method_get_resource_uid>`) for the purpose of network replication. When ``mode`` is :ref:`REPLICATION_MODE_SERVER<class_MultiplayerReplicator_constant_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<enum_@GlobalScope_Error>` **sync_all** **(** :ref:`int<class_int>` scene_id, :ref:`int<class_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<class_MultiplayerReplicator_method_sync_config>`.
- **Note:** The default implementation only allow syncing from server to clients.
- ----
- .. _class_MultiplayerReplicator_method_sync_config:
- - :ref:`Error<enum_@GlobalScope_Error>` **sync_config** **(** :ref:`int<class_int>` scene_id, :ref:`int<class_int>` interval, :ref:`StringName[]<class_StringName>` properties=[], :ref:`Callable<class_Callable>` custom_send, :ref:`Callable<class_Callable>` custom_receive **)**
- Configures the MultiplayerReplicator to sync instances of the :ref:`PackedScene<class_PackedScene>` identified by ``scene_id`` (see :ref:`ResourceLoader.get_resource_uid<class_ResourceLoader_method_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<class_int>` scene_id, :ref:`Object<class_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<class_MultiplayerReplicator_method_sync_config>`). Tracking and untracking is automatic in :ref:`REPLICATION_MODE_SERVER<class_MultiplayerReplicator_constant_REPLICATION_MODE_SERVER>`.
- ----
- .. _class_MultiplayerReplicator_method_untrack:
- - void **untrack** **(** :ref:`int<class_int>` scene_id, :ref:`Object<class_Object>` object **)**
- Untrack the given ``object``. This object will no longer be passed to your custom sync callables (see :ref:`sync_config<class_MultiplayerReplicator_method_sync_config>`). Tracking and untracking is automatic in :ref:`REPLICATION_MODE_SERVER<class_MultiplayerReplicator_constant_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.)`
|