class_multiplayersynchronizer.rst 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  1. :github_url: hide
  2. .. meta::
  3. :keywords: network
  4. .. DO NOT EDIT THIS FILE!!!
  5. .. Generated automatically from Godot engine sources.
  6. .. Generator: https://github.com/godotengine/godot/tree/master/doc/tools/make_rst.py.
  7. .. XML source: https://github.com/godotengine/godot/tree/master/modules/multiplayer/doc_classes/MultiplayerSynchronizer.xml.
  8. .. _class_MultiplayerSynchronizer:
  9. MultiplayerSynchronizer
  10. =======================
  11. **Inherits:** :ref:`Node<class_Node>` **<** :ref:`Object<class_Object>`
  12. Synchronizes properties from the multiplayer authority to the remote peers.
  13. .. rst-class:: classref-introduction-group
  14. Description
  15. -----------
  16. By default, **MultiplayerSynchronizer** synchronizes configured properties to all peers.
  17. Visibility can be handled directly with :ref:`set_visibility_for<class_MultiplayerSynchronizer_method_set_visibility_for>` or as-needed with :ref:`add_visibility_filter<class_MultiplayerSynchronizer_method_add_visibility_filter>` and :ref:`update_visibility<class_MultiplayerSynchronizer_method_update_visibility>`.
  18. \ :ref:`MultiplayerSpawner<class_MultiplayerSpawner>`\ s will handle nodes according to visibility of synchronizers as long as the node at :ref:`root_path<class_MultiplayerSynchronizer_property_root_path>` was spawned by one.
  19. Internally, **MultiplayerSynchronizer** uses :ref:`MultiplayerAPI.object_configuration_add<class_MultiplayerAPI_method_object_configuration_add>` to notify synchronization start passing the :ref:`Node<class_Node>` at :ref:`root_path<class_MultiplayerSynchronizer_property_root_path>` as the ``object`` and itself as the ``configuration``, and uses :ref:`MultiplayerAPI.object_configuration_remove<class_MultiplayerAPI_method_object_configuration_remove>` to notify synchronization end in a similar way.
  20. \ **Note:** Synchronization is not supported for :ref:`Object<class_Object>` type properties, like :ref:`Resource<class_Resource>`. Properties that are unique to each peer, like the instance IDs of :ref:`Object<class_Object>`\ s (see :ref:`Object.get_instance_id<class_Object_method_get_instance_id>`) or :ref:`RID<class_RID>`\ s, will also not work in synchronization.
  21. .. rst-class:: classref-reftable-group
  22. Properties
  23. ----------
  24. .. table::
  25. :widths: auto
  26. +--------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------+--------------------+
  27. | :ref:`float<class_float>` | :ref:`delta_interval<class_MultiplayerSynchronizer_property_delta_interval>` | ``0.0`` |
  28. +--------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------+--------------------+
  29. | :ref:`bool<class_bool>` | :ref:`public_visibility<class_MultiplayerSynchronizer_property_public_visibility>` | ``true`` |
  30. +--------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------+--------------------+
  31. | :ref:`SceneReplicationConfig<class_SceneReplicationConfig>` | :ref:`replication_config<class_MultiplayerSynchronizer_property_replication_config>` | |
  32. +--------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------+--------------------+
  33. | :ref:`float<class_float>` | :ref:`replication_interval<class_MultiplayerSynchronizer_property_replication_interval>` | ``0.0`` |
  34. +--------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------+--------------------+
  35. | :ref:`NodePath<class_NodePath>` | :ref:`root_path<class_MultiplayerSynchronizer_property_root_path>` | ``NodePath("..")`` |
  36. +--------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------+--------------------+
  37. | :ref:`VisibilityUpdateMode<enum_MultiplayerSynchronizer_VisibilityUpdateMode>` | :ref:`visibility_update_mode<class_MultiplayerSynchronizer_property_visibility_update_mode>` | ``0`` |
  38. +--------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------+--------------------+
  39. .. rst-class:: classref-reftable-group
  40. Methods
  41. -------
  42. .. table::
  43. :widths: auto
  44. +-------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------+
  45. | |void| | :ref:`add_visibility_filter<class_MultiplayerSynchronizer_method_add_visibility_filter>`\ (\ filter\: :ref:`Callable<class_Callable>`\ ) |
  46. +-------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------+
  47. | :ref:`bool<class_bool>` | :ref:`get_visibility_for<class_MultiplayerSynchronizer_method_get_visibility_for>`\ (\ peer\: :ref:`int<class_int>`\ ) |const| |
  48. +-------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------+
  49. | |void| | :ref:`remove_visibility_filter<class_MultiplayerSynchronizer_method_remove_visibility_filter>`\ (\ filter\: :ref:`Callable<class_Callable>`\ ) |
  50. +-------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------+
  51. | |void| | :ref:`set_visibility_for<class_MultiplayerSynchronizer_method_set_visibility_for>`\ (\ peer\: :ref:`int<class_int>`, visible\: :ref:`bool<class_bool>`\ ) |
  52. +-------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------+
  53. | |void| | :ref:`update_visibility<class_MultiplayerSynchronizer_method_update_visibility>`\ (\ for_peer\: :ref:`int<class_int>` = 0\ ) |
  54. +-------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------+
  55. .. rst-class:: classref-section-separator
  56. ----
  57. .. rst-class:: classref-descriptions-group
  58. Signals
  59. -------
  60. .. _class_MultiplayerSynchronizer_signal_delta_synchronized:
  61. .. rst-class:: classref-signal
  62. **delta_synchronized**\ (\ ) :ref:`🔗<class_MultiplayerSynchronizer_signal_delta_synchronized>`
  63. Emitted when a new delta synchronization state is received by this synchronizer after the properties have been updated.
  64. .. rst-class:: classref-item-separator
  65. ----
  66. .. _class_MultiplayerSynchronizer_signal_synchronized:
  67. .. rst-class:: classref-signal
  68. **synchronized**\ (\ ) :ref:`🔗<class_MultiplayerSynchronizer_signal_synchronized>`
  69. Emitted when a new synchronization state is received by this synchronizer after the properties have been updated.
  70. .. rst-class:: classref-item-separator
  71. ----
  72. .. _class_MultiplayerSynchronizer_signal_visibility_changed:
  73. .. rst-class:: classref-signal
  74. **visibility_changed**\ (\ for_peer\: :ref:`int<class_int>`\ ) :ref:`🔗<class_MultiplayerSynchronizer_signal_visibility_changed>`
  75. Emitted when visibility of ``for_peer`` is updated. See :ref:`update_visibility<class_MultiplayerSynchronizer_method_update_visibility>`.
  76. .. rst-class:: classref-section-separator
  77. ----
  78. .. rst-class:: classref-descriptions-group
  79. Enumerations
  80. ------------
  81. .. _enum_MultiplayerSynchronizer_VisibilityUpdateMode:
  82. .. rst-class:: classref-enumeration
  83. enum **VisibilityUpdateMode**: :ref:`🔗<enum_MultiplayerSynchronizer_VisibilityUpdateMode>`
  84. .. _class_MultiplayerSynchronizer_constant_VISIBILITY_PROCESS_IDLE:
  85. .. rst-class:: classref-enumeration-constant
  86. :ref:`VisibilityUpdateMode<enum_MultiplayerSynchronizer_VisibilityUpdateMode>` **VISIBILITY_PROCESS_IDLE** = ``0``
  87. Visibility filters are updated during process frames (see :ref:`Node.NOTIFICATION_INTERNAL_PROCESS<class_Node_constant_NOTIFICATION_INTERNAL_PROCESS>`).
  88. .. _class_MultiplayerSynchronizer_constant_VISIBILITY_PROCESS_PHYSICS:
  89. .. rst-class:: classref-enumeration-constant
  90. :ref:`VisibilityUpdateMode<enum_MultiplayerSynchronizer_VisibilityUpdateMode>` **VISIBILITY_PROCESS_PHYSICS** = ``1``
  91. Visibility filters are updated during physics frames (see :ref:`Node.NOTIFICATION_INTERNAL_PHYSICS_PROCESS<class_Node_constant_NOTIFICATION_INTERNAL_PHYSICS_PROCESS>`).
  92. .. _class_MultiplayerSynchronizer_constant_VISIBILITY_PROCESS_NONE:
  93. .. rst-class:: classref-enumeration-constant
  94. :ref:`VisibilityUpdateMode<enum_MultiplayerSynchronizer_VisibilityUpdateMode>` **VISIBILITY_PROCESS_NONE** = ``2``
  95. Visibility filters are not updated automatically, and must be updated manually by calling :ref:`update_visibility<class_MultiplayerSynchronizer_method_update_visibility>`.
  96. .. rst-class:: classref-section-separator
  97. ----
  98. .. rst-class:: classref-descriptions-group
  99. Property Descriptions
  100. ---------------------
  101. .. _class_MultiplayerSynchronizer_property_delta_interval:
  102. .. rst-class:: classref-property
  103. :ref:`float<class_float>` **delta_interval** = ``0.0`` :ref:`🔗<class_MultiplayerSynchronizer_property_delta_interval>`
  104. .. rst-class:: classref-property-setget
  105. - |void| **set_delta_interval**\ (\ value\: :ref:`float<class_float>`\ )
  106. - :ref:`float<class_float>` **get_delta_interval**\ (\ )
  107. Time interval between delta synchronizations. Used when the replication is set to :ref:`SceneReplicationConfig.REPLICATION_MODE_ON_CHANGE<class_SceneReplicationConfig_constant_REPLICATION_MODE_ON_CHANGE>`. If set to ``0.0`` (the default), delta synchronizations happen every network process frame.
  108. .. rst-class:: classref-item-separator
  109. ----
  110. .. _class_MultiplayerSynchronizer_property_public_visibility:
  111. .. rst-class:: classref-property
  112. :ref:`bool<class_bool>` **public_visibility** = ``true`` :ref:`🔗<class_MultiplayerSynchronizer_property_public_visibility>`
  113. .. rst-class:: classref-property-setget
  114. - |void| **set_visibility_public**\ (\ value\: :ref:`bool<class_bool>`\ )
  115. - :ref:`bool<class_bool>` **is_visibility_public**\ (\ )
  116. Whether synchronization should be visible to all peers by default. See :ref:`set_visibility_for<class_MultiplayerSynchronizer_method_set_visibility_for>` and :ref:`add_visibility_filter<class_MultiplayerSynchronizer_method_add_visibility_filter>` for ways of configuring fine-grained visibility options.
  117. .. rst-class:: classref-item-separator
  118. ----
  119. .. _class_MultiplayerSynchronizer_property_replication_config:
  120. .. rst-class:: classref-property
  121. :ref:`SceneReplicationConfig<class_SceneReplicationConfig>` **replication_config** :ref:`🔗<class_MultiplayerSynchronizer_property_replication_config>`
  122. .. rst-class:: classref-property-setget
  123. - |void| **set_replication_config**\ (\ value\: :ref:`SceneReplicationConfig<class_SceneReplicationConfig>`\ )
  124. - :ref:`SceneReplicationConfig<class_SceneReplicationConfig>` **get_replication_config**\ (\ )
  125. Resource containing which properties to synchronize.
  126. .. rst-class:: classref-item-separator
  127. ----
  128. .. _class_MultiplayerSynchronizer_property_replication_interval:
  129. .. rst-class:: classref-property
  130. :ref:`float<class_float>` **replication_interval** = ``0.0`` :ref:`🔗<class_MultiplayerSynchronizer_property_replication_interval>`
  131. .. rst-class:: classref-property-setget
  132. - |void| **set_replication_interval**\ (\ value\: :ref:`float<class_float>`\ )
  133. - :ref:`float<class_float>` **get_replication_interval**\ (\ )
  134. Time interval between synchronizations. Used when the replication is set to :ref:`SceneReplicationConfig.REPLICATION_MODE_ALWAYS<class_SceneReplicationConfig_constant_REPLICATION_MODE_ALWAYS>`. If set to ``0.0`` (the default), synchronizations happen every network process frame.
  135. .. rst-class:: classref-item-separator
  136. ----
  137. .. _class_MultiplayerSynchronizer_property_root_path:
  138. .. rst-class:: classref-property
  139. :ref:`NodePath<class_NodePath>` **root_path** = ``NodePath("..")`` :ref:`🔗<class_MultiplayerSynchronizer_property_root_path>`
  140. .. rst-class:: classref-property-setget
  141. - |void| **set_root_path**\ (\ value\: :ref:`NodePath<class_NodePath>`\ )
  142. - :ref:`NodePath<class_NodePath>` **get_root_path**\ (\ )
  143. Node path that replicated properties are relative to.
  144. If :ref:`root_path<class_MultiplayerSynchronizer_property_root_path>` was spawned by a :ref:`MultiplayerSpawner<class_MultiplayerSpawner>`, the node will be also be spawned and despawned based on this synchronizer visibility options.
  145. .. rst-class:: classref-item-separator
  146. ----
  147. .. _class_MultiplayerSynchronizer_property_visibility_update_mode:
  148. .. rst-class:: classref-property
  149. :ref:`VisibilityUpdateMode<enum_MultiplayerSynchronizer_VisibilityUpdateMode>` **visibility_update_mode** = ``0`` :ref:`🔗<class_MultiplayerSynchronizer_property_visibility_update_mode>`
  150. .. rst-class:: classref-property-setget
  151. - |void| **set_visibility_update_mode**\ (\ value\: :ref:`VisibilityUpdateMode<enum_MultiplayerSynchronizer_VisibilityUpdateMode>`\ )
  152. - :ref:`VisibilityUpdateMode<enum_MultiplayerSynchronizer_VisibilityUpdateMode>` **get_visibility_update_mode**\ (\ )
  153. Specifies when visibility filters are updated (see :ref:`VisibilityUpdateMode<enum_MultiplayerSynchronizer_VisibilityUpdateMode>` for options).
  154. .. rst-class:: classref-section-separator
  155. ----
  156. .. rst-class:: classref-descriptions-group
  157. Method Descriptions
  158. -------------------
  159. .. _class_MultiplayerSynchronizer_method_add_visibility_filter:
  160. .. rst-class:: classref-method
  161. |void| **add_visibility_filter**\ (\ filter\: :ref:`Callable<class_Callable>`\ ) :ref:`🔗<class_MultiplayerSynchronizer_method_add_visibility_filter>`
  162. Adds a peer visibility filter for this synchronizer.
  163. \ ``filter`` should take a peer ID :ref:`int<class_int>` and return a :ref:`bool<class_bool>`.
  164. .. rst-class:: classref-item-separator
  165. ----
  166. .. _class_MultiplayerSynchronizer_method_get_visibility_for:
  167. .. rst-class:: classref-method
  168. :ref:`bool<class_bool>` **get_visibility_for**\ (\ peer\: :ref:`int<class_int>`\ ) |const| :ref:`🔗<class_MultiplayerSynchronizer_method_get_visibility_for>`
  169. Queries the current visibility for peer ``peer``.
  170. .. rst-class:: classref-item-separator
  171. ----
  172. .. _class_MultiplayerSynchronizer_method_remove_visibility_filter:
  173. .. rst-class:: classref-method
  174. |void| **remove_visibility_filter**\ (\ filter\: :ref:`Callable<class_Callable>`\ ) :ref:`🔗<class_MultiplayerSynchronizer_method_remove_visibility_filter>`
  175. Removes a peer visibility filter from this synchronizer.
  176. .. rst-class:: classref-item-separator
  177. ----
  178. .. _class_MultiplayerSynchronizer_method_set_visibility_for:
  179. .. rst-class:: classref-method
  180. |void| **set_visibility_for**\ (\ peer\: :ref:`int<class_int>`, visible\: :ref:`bool<class_bool>`\ ) :ref:`🔗<class_MultiplayerSynchronizer_method_set_visibility_for>`
  181. Sets the visibility of ``peer`` to ``visible``. If ``peer`` is ``0``, the value of :ref:`public_visibility<class_MultiplayerSynchronizer_property_public_visibility>` will be updated instead.
  182. .. rst-class:: classref-item-separator
  183. ----
  184. .. _class_MultiplayerSynchronizer_method_update_visibility:
  185. .. rst-class:: classref-method
  186. |void| **update_visibility**\ (\ for_peer\: :ref:`int<class_int>` = 0\ ) :ref:`🔗<class_MultiplayerSynchronizer_method_update_visibility>`
  187. Updates the visibility of ``for_peer`` according to visibility filters. If ``for_peer`` is ``0`` (the default), all peers' visibilties are updated.
  188. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  189. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  190. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  191. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  192. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  193. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`
  194. .. |bitfield| replace:: :abbr:`BitField (This value is an integer composed as a bitmask of the following flags.)`
  195. .. |void| replace:: :abbr:`void (No return value.)`