class_scenemultiplayer.rst 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  1. :github_url: hide
  2. .. DO NOT EDIT THIS FILE!!!
  3. .. Generated automatically from Godot engine sources.
  4. .. Generator: https://github.com/godotengine/godot/tree/4.2/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/4.2/modules/multiplayer/doc_classes/SceneMultiplayer.xml.
  6. .. _class_SceneMultiplayer:
  7. SceneMultiplayer
  8. ================
  9. **Inherits:** :ref:`MultiplayerAPI<class_MultiplayerAPI>` **<** :ref:`RefCounted<class_RefCounted>` **<** :ref:`Object<class_Object>`
  10. High-level multiplayer API implementation.
  11. .. rst-class:: classref-introduction-group
  12. Description
  13. -----------
  14. This class is the default implementation of :ref:`MultiplayerAPI<class_MultiplayerAPI>`, used to provide multiplayer functionalities in Godot Engine.
  15. 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).
  16. 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.
  17. \ **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.
  18. \ **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.
  19. .. rst-class:: classref-reftable-group
  20. Properties
  21. ----------
  22. .. table::
  23. :widths: auto
  24. +---------------------------------+---------------------------------------------------------------------------------------+------------------+
  25. | :ref:`bool<class_bool>` | :ref:`allow_object_decoding<class_SceneMultiplayer_property_allow_object_decoding>` | ``false`` |
  26. +---------------------------------+---------------------------------------------------------------------------------------+------------------+
  27. | :ref:`Callable<class_Callable>` | :ref:`auth_callback<class_SceneMultiplayer_property_auth_callback>` | ``Callable()`` |
  28. +---------------------------------+---------------------------------------------------------------------------------------+------------------+
  29. | :ref:`float<class_float>` | :ref:`auth_timeout<class_SceneMultiplayer_property_auth_timeout>` | ``3.0`` |
  30. +---------------------------------+---------------------------------------------------------------------------------------+------------------+
  31. | :ref:`int<class_int>` | :ref:`max_delta_packet_size<class_SceneMultiplayer_property_max_delta_packet_size>` | ``65535`` |
  32. +---------------------------------+---------------------------------------------------------------------------------------+------------------+
  33. | :ref:`int<class_int>` | :ref:`max_sync_packet_size<class_SceneMultiplayer_property_max_sync_packet_size>` | ``1350`` |
  34. +---------------------------------+---------------------------------------------------------------------------------------+------------------+
  35. | :ref:`bool<class_bool>` | :ref:`refuse_new_connections<class_SceneMultiplayer_property_refuse_new_connections>` | ``false`` |
  36. +---------------------------------+---------------------------------------------------------------------------------------+------------------+
  37. | :ref:`NodePath<class_NodePath>` | :ref:`root_path<class_SceneMultiplayer_property_root_path>` | ``NodePath("")`` |
  38. +---------------------------------+---------------------------------------------------------------------------------------+------------------+
  39. | :ref:`bool<class_bool>` | :ref:`server_relay<class_SceneMultiplayer_property_server_relay>` | ``true`` |
  40. +---------------------------------+---------------------------------------------------------------------------------------+------------------+
  41. .. rst-class:: classref-reftable-group
  42. Methods
  43. -------
  44. .. table::
  45. :widths: auto
  46. +-------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  47. | void | :ref:`clear<class_SceneMultiplayer_method_clear>` **(** **)** |
  48. +-------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  49. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`complete_auth<class_SceneMultiplayer_method_complete_auth>` **(** :ref:`int<class_int>` id **)** |
  50. +-------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  51. | void | :ref:`disconnect_peer<class_SceneMultiplayer_method_disconnect_peer>` **(** :ref:`int<class_int>` id **)** |
  52. +-------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  53. | :ref:`PackedInt32Array<class_PackedInt32Array>` | :ref:`get_authenticating_peers<class_SceneMultiplayer_method_get_authenticating_peers>` **(** **)** |
  54. +-------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  55. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`send_auth<class_SceneMultiplayer_method_send_auth>` **(** :ref:`int<class_int>` id, :ref:`PackedByteArray<class_PackedByteArray>` data **)** |
  56. +-------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  57. | :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 **)** |
  58. +-------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  59. .. rst-class:: classref-section-separator
  60. ----
  61. .. rst-class:: classref-descriptions-group
  62. Signals
  63. -------
  64. .. _class_SceneMultiplayer_signal_peer_authenticating:
  65. .. rst-class:: classref-signal
  66. **peer_authenticating** **(** :ref:`int<class_int>` id **)**
  67. 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.
  68. .. rst-class:: classref-item-separator
  69. ----
  70. .. _class_SceneMultiplayer_signal_peer_authentication_failed:
  71. .. rst-class:: classref-signal
  72. **peer_authentication_failed** **(** :ref:`int<class_int>` id **)**
  73. 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>`.
  74. .. rst-class:: classref-item-separator
  75. ----
  76. .. _class_SceneMultiplayer_signal_peer_packet:
  77. .. rst-class:: classref-signal
  78. **peer_packet** **(** :ref:`int<class_int>` id, :ref:`PackedByteArray<class_PackedByteArray>` packet **)**
  79. 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.
  80. .. rst-class:: classref-section-separator
  81. ----
  82. .. rst-class:: classref-descriptions-group
  83. Property Descriptions
  84. ---------------------
  85. .. _class_SceneMultiplayer_property_allow_object_decoding:
  86. .. rst-class:: classref-property
  87. :ref:`bool<class_bool>` **allow_object_decoding** = ``false``
  88. .. rst-class:: classref-property-setget
  89. - void **set_allow_object_decoding** **(** :ref:`bool<class_bool>` value **)**
  90. - :ref:`bool<class_bool>` **is_object_decoding_allowed** **(** **)**
  91. If ``true``, the MultiplayerAPI will allow encoding and decoding of object during RPCs.
  92. \ **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.
  93. .. rst-class:: classref-item-separator
  94. ----
  95. .. _class_SceneMultiplayer_property_auth_callback:
  96. .. rst-class:: classref-property
  97. :ref:`Callable<class_Callable>` **auth_callback** = ``Callable()``
  98. .. rst-class:: classref-property-setget
  99. - void **set_auth_callback** **(** :ref:`Callable<class_Callable>` value **)**
  100. - :ref:`Callable<class_Callable>` **get_auth_callback** **(** **)**
  101. 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.
  102. .. rst-class:: classref-item-separator
  103. ----
  104. .. _class_SceneMultiplayer_property_auth_timeout:
  105. .. rst-class:: classref-property
  106. :ref:`float<class_float>` **auth_timeout** = ``3.0``
  107. .. rst-class:: classref-property-setget
  108. - void **set_auth_timeout** **(** :ref:`float<class_float>` value **)**
  109. - :ref:`float<class_float>` **get_auth_timeout** **(** **)**
  110. 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.
  111. .. rst-class:: classref-item-separator
  112. ----
  113. .. _class_SceneMultiplayer_property_max_delta_packet_size:
  114. .. rst-class:: classref-property
  115. :ref:`int<class_int>` **max_delta_packet_size** = ``65535``
  116. .. rst-class:: classref-property-setget
  117. - void **set_max_delta_packet_size** **(** :ref:`int<class_int>` value **)**
  118. - :ref:`int<class_int>` **get_max_delta_packet_size** **(** **)**
  119. 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>`.
  120. .. rst-class:: classref-item-separator
  121. ----
  122. .. _class_SceneMultiplayer_property_max_sync_packet_size:
  123. .. rst-class:: classref-property
  124. :ref:`int<class_int>` **max_sync_packet_size** = ``1350``
  125. .. rst-class:: classref-property-setget
  126. - void **set_max_sync_packet_size** **(** :ref:`int<class_int>` value **)**
  127. - :ref:`int<class_int>` **get_max_sync_packet_size** **(** **)**
  128. 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>`.
  129. .. rst-class:: classref-item-separator
  130. ----
  131. .. _class_SceneMultiplayer_property_refuse_new_connections:
  132. .. rst-class:: classref-property
  133. :ref:`bool<class_bool>` **refuse_new_connections** = ``false``
  134. .. rst-class:: classref-property-setget
  135. - void **set_refuse_new_connections** **(** :ref:`bool<class_bool>` value **)**
  136. - :ref:`bool<class_bool>` **is_refusing_new_connections** **(** **)**
  137. If ``true``, the MultiplayerAPI's :ref:`MultiplayerAPI.multiplayer_peer<class_MultiplayerAPI_property_multiplayer_peer>` refuses new incoming connections.
  138. .. rst-class:: classref-item-separator
  139. ----
  140. .. _class_SceneMultiplayer_property_root_path:
  141. .. rst-class:: classref-property
  142. :ref:`NodePath<class_NodePath>` **root_path** = ``NodePath("")``
  143. .. rst-class:: classref-property-setget
  144. - void **set_root_path** **(** :ref:`NodePath<class_NodePath>` value **)**
  145. - :ref:`NodePath<class_NodePath>` **get_root_path** **(** **)**
  146. 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.
  147. 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.
  148. .. rst-class:: classref-item-separator
  149. ----
  150. .. _class_SceneMultiplayer_property_server_relay:
  151. .. rst-class:: classref-property
  152. :ref:`bool<class_bool>` **server_relay** = ``true``
  153. .. rst-class:: classref-property-setget
  154. - void **set_server_relay_enabled** **(** :ref:`bool<class_bool>` value **)**
  155. - :ref:`bool<class_bool>` **is_server_relay_enabled** **(** **)**
  156. 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.
  157. \ **Note:** Changing this option while other peers are connected may lead to unexpected behaviors.
  158. \ **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>`.
  159. .. rst-class:: classref-section-separator
  160. ----
  161. .. rst-class:: classref-descriptions-group
  162. Method Descriptions
  163. -------------------
  164. .. _class_SceneMultiplayer_method_clear:
  165. .. rst-class:: classref-method
  166. void **clear** **(** **)**
  167. Clears the current SceneMultiplayer network state (you shouldn't call this unless you know what you are doing).
  168. .. rst-class:: classref-item-separator
  169. ----
  170. .. _class_SceneMultiplayer_method_complete_auth:
  171. .. rst-class:: classref-method
  172. :ref:`Error<enum_@GlobalScope_Error>` **complete_auth** **(** :ref:`int<class_int>` id **)**
  173. 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.
  174. 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>`.
  175. .. rst-class:: classref-item-separator
  176. ----
  177. .. _class_SceneMultiplayer_method_disconnect_peer:
  178. .. rst-class:: classref-method
  179. void **disconnect_peer** **(** :ref:`int<class_int>` id **)**
  180. Disconnects the peer identified by ``id``, removing it from the list of connected peers, and closing the underlying connection with it.
  181. .. rst-class:: classref-item-separator
  182. ----
  183. .. _class_SceneMultiplayer_method_get_authenticating_peers:
  184. .. rst-class:: classref-method
  185. :ref:`PackedInt32Array<class_PackedInt32Array>` **get_authenticating_peers** **(** **)**
  186. Returns the IDs of the peers currently trying to authenticate with this :ref:`MultiplayerAPI<class_MultiplayerAPI>`.
  187. .. rst-class:: classref-item-separator
  188. ----
  189. .. _class_SceneMultiplayer_method_send_auth:
  190. .. rst-class:: classref-method
  191. :ref:`Error<enum_@GlobalScope_Error>` **send_auth** **(** :ref:`int<class_int>` id, :ref:`PackedByteArray<class_PackedByteArray>` data **)**
  192. 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).
  193. .. rst-class:: classref-item-separator
  194. ----
  195. .. _class_SceneMultiplayer_method_send_bytes:
  196. .. rst-class:: classref-method
  197. :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 **)**
  198. 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.
  199. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  200. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  201. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  202. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  203. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  204. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`
  205. .. |bitfield| replace:: :abbr:`BitField (This value is an integer composed as a bitmask of the following flags.)`