123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356 |
- :github_url: hide
- .. DO NOT EDIT THIS FILE!!!
- .. Generated automatically from Godot engine sources.
- .. Generator: https://github.com/godotengine/godot/tree/4.2/doc/tools/make_rst.py.
- .. XML source: https://github.com/godotengine/godot/tree/4.2/modules/multiplayer/doc_classes/SceneMultiplayer.xml.
- .. _class_SceneMultiplayer:
- SceneMultiplayer
- ================
- **Inherits:** :ref:`MultiplayerAPI<class_MultiplayerAPI>` **<** :ref:`RefCounted<class_RefCounted>` **<** :ref:`Object<class_Object>`
- High-level multiplayer API implementation.
- .. rst-class:: classref-introduction-group
- Description
- -----------
- This class is the default implementation of :ref:`MultiplayerAPI<class_MultiplayerAPI>`, used to provide multiplayer functionalities in Godot Engine.
- This implementation supports RPCs via :ref:`Node.rpc<class_Node_method_rpc>` and :ref:`Node.rpc_id<class_Node_method_rpc_id>` and requires :ref:`MultiplayerAPI.rpc<class_MultiplayerAPI_method_rpc>` to be passed a :ref:`Node<class_Node>` (it will fail for other object types).
- This implementation additionally provide :ref:`SceneTree<class_SceneTree>` replication via the :ref:`MultiplayerSpawner<class_MultiplayerSpawner>` and :ref:`MultiplayerSynchronizer<class_MultiplayerSynchronizer>` nodes, and the :ref:`SceneReplicationConfig<class_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.
- .. rst-class:: classref-reftable-group
- Properties
- ----------
- .. table::
- :widths: auto
- +---------------------------------+---------------------------------------------------------------------------------------+------------------+
- | :ref:`bool<class_bool>` | :ref:`allow_object_decoding<class_SceneMultiplayer_property_allow_object_decoding>` | ``false`` |
- +---------------------------------+---------------------------------------------------------------------------------------+------------------+
- | :ref:`Callable<class_Callable>` | :ref:`auth_callback<class_SceneMultiplayer_property_auth_callback>` | ``Callable()`` |
- +---------------------------------+---------------------------------------------------------------------------------------+------------------+
- | :ref:`float<class_float>` | :ref:`auth_timeout<class_SceneMultiplayer_property_auth_timeout>` | ``3.0`` |
- +---------------------------------+---------------------------------------------------------------------------------------+------------------+
- | :ref:`int<class_int>` | :ref:`max_delta_packet_size<class_SceneMultiplayer_property_max_delta_packet_size>` | ``65535`` |
- +---------------------------------+---------------------------------------------------------------------------------------+------------------+
- | :ref:`int<class_int>` | :ref:`max_sync_packet_size<class_SceneMultiplayer_property_max_sync_packet_size>` | ``1350`` |
- +---------------------------------+---------------------------------------------------------------------------------------+------------------+
- | :ref:`bool<class_bool>` | :ref:`refuse_new_connections<class_SceneMultiplayer_property_refuse_new_connections>` | ``false`` |
- +---------------------------------+---------------------------------------------------------------------------------------+------------------+
- | :ref:`NodePath<class_NodePath>` | :ref:`root_path<class_SceneMultiplayer_property_root_path>` | ``NodePath("")`` |
- +---------------------------------+---------------------------------------------------------------------------------------+------------------+
- | :ref:`bool<class_bool>` | :ref:`server_relay<class_SceneMultiplayer_property_server_relay>` | ``true`` |
- +---------------------------------+---------------------------------------------------------------------------------------+------------------+
- .. rst-class:: classref-reftable-group
- Methods
- -------
- .. table::
- :widths: auto
- +-------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | void | :ref:`clear<class_SceneMultiplayer_method_clear>` **(** **)** |
- +-------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`complete_auth<class_SceneMultiplayer_method_complete_auth>` **(** :ref:`int<class_int>` id **)** |
- +-------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | void | :ref:`disconnect_peer<class_SceneMultiplayer_method_disconnect_peer>` **(** :ref:`int<class_int>` id **)** |
- +-------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`PackedInt32Array<class_PackedInt32Array>` | :ref:`get_authenticating_peers<class_SceneMultiplayer_method_get_authenticating_peers>` **(** **)** |
- +-------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`send_auth<class_SceneMultiplayer_method_send_auth>` **(** :ref:`int<class_int>` id, :ref:`PackedByteArray<class_PackedByteArray>` data **)** |
- +-------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`send_bytes<class_SceneMultiplayer_method_send_bytes>` **(** :ref:`PackedByteArray<class_PackedByteArray>` bytes, :ref:`int<class_int>` id=0, :ref:`TransferMode<enum_MultiplayerPeer_TransferMode>` mode=2, :ref:`int<class_int>` channel=0 **)** |
- +-------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- .. rst-class:: classref-section-separator
- ----
- .. rst-class:: classref-descriptions-group
- Signals
- -------
- .. _class_SceneMultiplayer_signal_peer_authenticating:
- .. rst-class:: classref-signal
- **peer_authenticating** **(** :ref:`int<class_int>` id **)**
- Emitted when this MultiplayerAPI's :ref:`MultiplayerAPI.multiplayer_peer<class_MultiplayerAPI_property_multiplayer_peer>` connects to a new peer and a valid :ref:`auth_callback<class_SceneMultiplayer_property_auth_callback>` is set. In this case, the :ref:`MultiplayerAPI.peer_connected<class_MultiplayerAPI_signal_peer_connected>` will not be emitted until :ref:`complete_auth<class_SceneMultiplayer_method_complete_auth>` is called with given peer ``id``. While in this state, the peer will not be included in the list returned by :ref:`MultiplayerAPI.get_peers<class_MultiplayerAPI_method_get_peers>` (but in the one returned by :ref:`get_authenticating_peers<class_SceneMultiplayer_method_get_authenticating_peers>`), and only authentication data will be sent or received. See :ref:`send_auth<class_SceneMultiplayer_method_send_auth>` for sending authentication data.
- .. rst-class:: classref-item-separator
- ----
- .. _class_SceneMultiplayer_signal_peer_authentication_failed:
- .. rst-class:: classref-signal
- **peer_authentication_failed** **(** :ref:`int<class_int>` id **)**
- Emitted when this MultiplayerAPI's :ref:`MultiplayerAPI.multiplayer_peer<class_MultiplayerAPI_property_multiplayer_peer>` disconnects from a peer for which authentication had not yet completed. See :ref:`peer_authenticating<class_SceneMultiplayer_signal_peer_authenticating>`.
- .. rst-class:: classref-item-separator
- ----
- .. _class_SceneMultiplayer_signal_peer_packet:
- .. rst-class:: classref-signal
- **peer_packet** **(** :ref:`int<class_int>` id, :ref:`PackedByteArray<class_PackedByteArray>` packet **)**
- Emitted when this MultiplayerAPI's :ref:`MultiplayerAPI.multiplayer_peer<class_MultiplayerAPI_property_multiplayer_peer>` receives a ``packet`` with custom data (see :ref:`send_bytes<class_SceneMultiplayer_method_send_bytes>`). ID is the peer ID of the peer that sent the packet.
- .. rst-class:: classref-section-separator
- ----
- .. rst-class:: classref-descriptions-group
- Property Descriptions
- ---------------------
- .. _class_SceneMultiplayer_property_allow_object_decoding:
- .. rst-class:: classref-property
- :ref:`bool<class_bool>` **allow_object_decoding** = ``false``
- .. rst-class:: classref-property-setget
- - void **set_allow_object_decoding** **(** :ref:`bool<class_bool>` value **)**
- - :ref:`bool<class_bool>` **is_object_decoding_allowed** **(** **)**
- 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.
- .. rst-class:: classref-item-separator
- ----
- .. _class_SceneMultiplayer_property_auth_callback:
- .. rst-class:: classref-property
- :ref:`Callable<class_Callable>` **auth_callback** = ``Callable()``
- .. rst-class:: classref-property-setget
- - void **set_auth_callback** **(** :ref:`Callable<class_Callable>` value **)**
- - :ref:`Callable<class_Callable>` **get_auth_callback** **(** **)**
- The callback to execute when when receiving authentication data sent via :ref:`send_auth<class_SceneMultiplayer_method_send_auth>`. If the :ref:`Callable<class_Callable>` is empty (default), peers will be automatically accepted as soon as they connect.
- .. rst-class:: classref-item-separator
- ----
- .. _class_SceneMultiplayer_property_auth_timeout:
- .. rst-class:: classref-property
- :ref:`float<class_float>` **auth_timeout** = ``3.0``
- .. rst-class:: classref-property-setget
- - void **set_auth_timeout** **(** :ref:`float<class_float>` value **)**
- - :ref:`float<class_float>` **get_auth_timeout** **(** **)**
- 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 :ref:`peer_authenticating<class_SceneMultiplayer_signal_peer_authenticating>` and :ref:`peer_authentication_failed<class_SceneMultiplayer_signal_peer_authentication_failed>` signals.
- .. rst-class:: classref-item-separator
- ----
- .. _class_SceneMultiplayer_property_max_delta_packet_size:
- .. rst-class:: classref-property
- :ref:`int<class_int>` **max_delta_packet_size** = ``65535``
- .. rst-class:: classref-property-setget
- - void **set_max_delta_packet_size** **(** :ref:`int<class_int>` value **)**
- - :ref:`int<class_int>` **get_max_delta_packet_size** **(** **)**
- 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 :ref:`MultiplayerSynchronizer<class_MultiplayerSynchronizer>`.
- .. rst-class:: classref-item-separator
- ----
- .. _class_SceneMultiplayer_property_max_sync_packet_size:
- .. rst-class:: classref-property
- :ref:`int<class_int>` **max_sync_packet_size** = ``1350``
- .. rst-class:: classref-property-setget
- - void **set_max_sync_packet_size** **(** :ref:`int<class_int>` value **)**
- - :ref:`int<class_int>` **get_max_sync_packet_size** **(** **)**
- 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 :ref:`MultiplayerSynchronizer<class_MultiplayerSynchronizer>`.
- .. rst-class:: classref-item-separator
- ----
- .. _class_SceneMultiplayer_property_refuse_new_connections:
- .. rst-class:: classref-property
- :ref:`bool<class_bool>` **refuse_new_connections** = ``false``
- .. rst-class:: classref-property-setget
- - void **set_refuse_new_connections** **(** :ref:`bool<class_bool>` value **)**
- - :ref:`bool<class_bool>` **is_refusing_new_connections** **(** **)**
- If ``true``, the MultiplayerAPI's :ref:`MultiplayerAPI.multiplayer_peer<class_MultiplayerAPI_property_multiplayer_peer>` refuses new incoming connections.
- .. rst-class:: classref-item-separator
- ----
- .. _class_SceneMultiplayer_property_root_path:
- .. rst-class:: classref-property
- :ref:`NodePath<class_NodePath>` **root_path** = ``NodePath("")``
- .. rst-class:: classref-property-setget
- - void **set_root_path** **(** :ref:`NodePath<class_NodePath>` value **)**
- - :ref:`NodePath<class_NodePath>` **get_root_path** **(** **)**
- 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.
- .. rst-class:: classref-item-separator
- ----
- .. _class_SceneMultiplayer_property_server_relay:
- .. rst-class:: classref-property
- :ref:`bool<class_bool>` **server_relay** = ``true``
- .. rst-class:: classref-property-setget
- - void **set_server_relay_enabled** **(** :ref:`bool<class_bool>` value **)**
- - :ref:`bool<class_bool>` **is_server_relay_enabled** **(** **)**
- 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 :ref:`MultiplayerPeer<class_MultiplayerPeer>` configuration. See :ref:`MultiplayerPeer.is_server_relay_supported<class_MultiplayerPeer_method_is_server_relay_supported>`.
- .. rst-class:: classref-section-separator
- ----
- .. rst-class:: classref-descriptions-group
- Method Descriptions
- -------------------
- .. _class_SceneMultiplayer_method_clear:
- .. rst-class:: classref-method
- void **clear** **(** **)**
- Clears the current SceneMultiplayer network state (you shouldn't call this unless you know what you are doing).
- .. rst-class:: classref-item-separator
- ----
- .. _class_SceneMultiplayer_method_complete_auth:
- .. rst-class:: classref-method
- :ref:`Error<enum_@GlobalScope_Error>` **complete_auth** **(** :ref:`int<class_int>` id **)**
- Mark the authentication step as completed for the remote peer identified by ``id``. The :ref:`MultiplayerAPI.peer_connected<class_MultiplayerAPI_signal_peer_connected>` 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 :ref:`auth_timeout<class_SceneMultiplayer_property_auth_timeout>` expiring, or manually calling :ref:`disconnect_peer<class_SceneMultiplayer_method_disconnect_peer>`, the :ref:`peer_authentication_failed<class_SceneMultiplayer_signal_peer_authentication_failed>` signal will be emitted instead of :ref:`MultiplayerAPI.peer_disconnected<class_MultiplayerAPI_signal_peer_disconnected>`.
- .. rst-class:: classref-item-separator
- ----
- .. _class_SceneMultiplayer_method_disconnect_peer:
- .. rst-class:: classref-method
- void **disconnect_peer** **(** :ref:`int<class_int>` id **)**
- Disconnects the peer identified by ``id``, removing it from the list of connected peers, and closing the underlying connection with it.
- .. rst-class:: classref-item-separator
- ----
- .. _class_SceneMultiplayer_method_get_authenticating_peers:
- .. rst-class:: classref-method
- :ref:`PackedInt32Array<class_PackedInt32Array>` **get_authenticating_peers** **(** **)**
- Returns the IDs of the peers currently trying to authenticate with this :ref:`MultiplayerAPI<class_MultiplayerAPI>`.
- .. rst-class:: classref-item-separator
- ----
- .. _class_SceneMultiplayer_method_send_auth:
- .. rst-class:: classref-method
- :ref:`Error<enum_@GlobalScope_Error>` **send_auth** **(** :ref:`int<class_int>` id, :ref:`PackedByteArray<class_PackedByteArray>` 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 :ref:`MultiplayerAPI.peer_connected<class_MultiplayerAPI_signal_peer_connected>` is emitted (and the remote peer accepted as one of the connected peers).
- .. rst-class:: classref-item-separator
- ----
- .. _class_SceneMultiplayer_method_send_bytes:
- .. rst-class:: classref-method
- :ref:`Error<enum_@GlobalScope_Error>` **send_bytes** **(** :ref:`PackedByteArray<class_PackedByteArray>` bytes, :ref:`int<class_int>` id=0, :ref:`TransferMode<enum_MultiplayerPeer_TransferMode>` mode=2, :ref:`int<class_int>` channel=0 **)**
- Sends the given raw ``bytes`` to a specific peer identified by ``id`` (see :ref:`MultiplayerPeer.set_target_peer<class_MultiplayerPeer_method_set_target_peer>`). Default ID is ``0``, i.e. broadcast to all peers.
- .. |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.)`
- .. |bitfield| replace:: :abbr:`BitField (This value is an integer composed as a bitmask of the following flags.)`
|