:github_url: hide .. meta:: :keywords: network .. DO NOT EDIT THIS FILE!!! .. Generated automatically from Godot engine sources. .. Generator: https://github.com/godotengine/godot/tree/master/doc/tools/make_rst.py. .. XML source: https://github.com/godotengine/godot/tree/master/modules/multiplayer/doc_classes/MultiplayerSpawner.xml. .. _class_MultiplayerSpawner: MultiplayerSpawner ================== **Inherits:** :ref:`Node` **<** :ref:`Object` Automatically replicates spawnable nodes from the authority to other multiplayer peers. .. rst-class:: classref-introduction-group Description ----------- Spawnable scenes can be configured in the editor or through code (see :ref:`add_spawnable_scene()`). Also supports custom node spawns through :ref:`spawn()`, calling :ref:`spawn_function` on all peers. Internally, **MultiplayerSpawner** uses :ref:`MultiplayerAPI.object_configuration_add()` to notify spawns passing the spawned node as the ``object`` and itself as the ``configuration``, and :ref:`MultiplayerAPI.object_configuration_remove()` to notify despawns in a similar way. .. rst-class:: classref-reftable-group Properties ---------- .. table:: :widths: auto +---------------------------------+-------------------------------------------------------------------------+------------------+ | :ref:`Callable` | :ref:`spawn_function` | | +---------------------------------+-------------------------------------------------------------------------+------------------+ | :ref:`int` | :ref:`spawn_limit` | ``0`` | +---------------------------------+-------------------------------------------------------------------------+------------------+ | :ref:`NodePath` | :ref:`spawn_path` | ``NodePath("")`` | +---------------------------------+-------------------------------------------------------------------------+------------------+ .. rst-class:: classref-reftable-group Methods ------- .. table:: :widths: auto +-----------------------------+------------------------------------------------------------------------------------------------------------------------------+ | |void| | :ref:`add_spawnable_scene`\ (\ path\: :ref:`String`\ ) | +-----------------------------+------------------------------------------------------------------------------------------------------------------------------+ | |void| | :ref:`clear_spawnable_scenes`\ (\ ) | +-----------------------------+------------------------------------------------------------------------------------------------------------------------------+ | :ref:`String` | :ref:`get_spawnable_scene`\ (\ index\: :ref:`int`\ ) |const| | +-----------------------------+------------------------------------------------------------------------------------------------------------------------------+ | :ref:`int` | :ref:`get_spawnable_scene_count`\ (\ ) |const| | +-----------------------------+------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Node` | :ref:`spawn`\ (\ data\: :ref:`Variant` = null\ ) | +-----------------------------+------------------------------------------------------------------------------------------------------------------------------+ .. rst-class:: classref-section-separator ---- .. rst-class:: classref-descriptions-group Signals ------- .. _class_MultiplayerSpawner_signal_despawned: .. rst-class:: classref-signal **despawned**\ (\ node\: :ref:`Node`\ ) :ref:`🔗` Emitted when a spawnable scene or custom spawn was despawned by the multiplayer authority. Only called on remote peers. .. rst-class:: classref-item-separator ---- .. _class_MultiplayerSpawner_signal_spawned: .. rst-class:: classref-signal **spawned**\ (\ node\: :ref:`Node`\ ) :ref:`🔗` Emitted when a spawnable scene or custom spawn was spawned by the multiplayer authority. Only called on remote peers. .. rst-class:: classref-section-separator ---- .. rst-class:: classref-descriptions-group Property Descriptions --------------------- .. _class_MultiplayerSpawner_property_spawn_function: .. rst-class:: classref-property :ref:`Callable` **spawn_function** :ref:`🔗` .. rst-class:: classref-property-setget - |void| **set_spawn_function**\ (\ value\: :ref:`Callable`\ ) - :ref:`Callable` **get_spawn_function**\ (\ ) Method called on all peers when a custom :ref:`spawn()` is requested by the authority. Will receive the ``data`` parameter, and should return a :ref:`Node` that is not in the scene tree. \ **Note:** The returned node should **not** be added to the scene with :ref:`Node.add_child()`. This is done automatically. .. rst-class:: classref-item-separator ---- .. _class_MultiplayerSpawner_property_spawn_limit: .. rst-class:: classref-property :ref:`int` **spawn_limit** = ``0`` :ref:`🔗` .. rst-class:: classref-property-setget - |void| **set_spawn_limit**\ (\ value\: :ref:`int`\ ) - :ref:`int` **get_spawn_limit**\ (\ ) Maximum number of nodes allowed to be spawned by this spawner. Includes both spawnable scenes and custom spawns. When set to ``0`` (the default), there is no limit. .. rst-class:: classref-item-separator ---- .. _class_MultiplayerSpawner_property_spawn_path: .. rst-class:: classref-property :ref:`NodePath` **spawn_path** = ``NodePath("")`` :ref:`🔗` .. rst-class:: classref-property-setget - |void| **set_spawn_path**\ (\ value\: :ref:`NodePath`\ ) - :ref:`NodePath` **get_spawn_path**\ (\ ) Path to the spawn root. Spawnable scenes that are added as direct children are replicated to other peers. .. rst-class:: classref-section-separator ---- .. rst-class:: classref-descriptions-group Method Descriptions ------------------- .. _class_MultiplayerSpawner_method_add_spawnable_scene: .. rst-class:: classref-method |void| **add_spawnable_scene**\ (\ path\: :ref:`String`\ ) :ref:`🔗` Adds a scene path to spawnable scenes, making it automatically replicated from the multiplayer authority to other peers when added as children of the node pointed by :ref:`spawn_path`. .. rst-class:: classref-item-separator ---- .. _class_MultiplayerSpawner_method_clear_spawnable_scenes: .. rst-class:: classref-method |void| **clear_spawnable_scenes**\ (\ ) :ref:`🔗` Clears all spawnable scenes. Does not despawn existing instances on remote peers. .. rst-class:: classref-item-separator ---- .. _class_MultiplayerSpawner_method_get_spawnable_scene: .. rst-class:: classref-method :ref:`String` **get_spawnable_scene**\ (\ index\: :ref:`int`\ ) |const| :ref:`🔗` Returns the spawnable scene path by index. .. rst-class:: classref-item-separator ---- .. _class_MultiplayerSpawner_method_get_spawnable_scene_count: .. rst-class:: classref-method :ref:`int` **get_spawnable_scene_count**\ (\ ) |const| :ref:`🔗` Returns the count of spawnable scene paths. .. rst-class:: classref-item-separator ---- .. _class_MultiplayerSpawner_method_spawn: .. rst-class:: classref-method :ref:`Node` **spawn**\ (\ data\: :ref:`Variant` = null\ ) :ref:`🔗` Requests a custom spawn, with ``data`` passed to :ref:`spawn_function` on all peers. Returns the locally spawned node instance already inside the scene tree, and added as a child of the node pointed by :ref:`spawn_path`. \ **Note:** Spawnable scenes are spawned automatically. :ref:`spawn()` is only needed for custom spawns. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)` .. |required| replace:: :abbr:`required (This method is required to be overridden when extending its base class.)` .. |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.)` .. |void| replace:: :abbr:`void (No return value.)`