diff options
author | Fabio Alessandrelli <fabio.alessandrelli@gmail.com> | 2023-02-12 15:15:10 +0100 |
---|---|---|
committer | Fabio Alessandrelli <fabio.alessandrelli@gmail.com> | 2023-02-12 15:32:09 +0100 |
commit | a77820ade0cb0c807c63aa9cd94d49280e181fac (patch) | |
tree | 6e531a1fddafd464d3265be6c8eb70a53f6eae96 /modules/multiplayer | |
parent | 3fcd98997257a6b856d70a3cf8846c5ac282f823 (diff) |
[MP] Fix MultiplayerSpawner not connecting to child_entered_tree.
The connection used to happen during enter_tree, but this was causing
issues when setting the spawnable scenes from code.
The spawner now connects/disconnects to the signal during
add_spawnable_scene/clear_spawnable_scenes if the node is inside tree
and has a valid spawn_path.
Diffstat (limited to 'modules/multiplayer')
-rw-r--r-- | modules/multiplayer/multiplayer_spawner.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/modules/multiplayer/multiplayer_spawner.cpp b/modules/multiplayer/multiplayer_spawner.cpp index 0aa54b69f9..4b1b6b541d 100644 --- a/modules/multiplayer/multiplayer_spawner.cpp +++ b/modules/multiplayer/multiplayer_spawner.cpp @@ -103,6 +103,15 @@ void MultiplayerSpawner::add_spawnable_scene(const String &p_path) { ERR_FAIL_COND(!FileAccess::exists(p_path)); } spawnable_scenes.push_back(sc); +#ifdef TOOLS_ENABLED + if (Engine::get_singleton()->is_editor_hint()) { + return; + } +#endif + Node *node = get_spawn_node(); + if (spawnable_scenes.size() == 1 && node && !node->is_connected("child_entered_tree", callable_mp(this, &MultiplayerSpawner::_node_added))) { + node->connect("child_entered_tree", callable_mp(this, &MultiplayerSpawner::_node_added)); + } } int MultiplayerSpawner::get_spawnable_scene_count() const { @@ -116,6 +125,15 @@ String MultiplayerSpawner::get_spawnable_scene(int p_idx) const { void MultiplayerSpawner::clear_spawnable_scenes() { spawnable_scenes.clear(); +#ifdef TOOLS_ENABLED + if (Engine::get_singleton()->is_editor_hint()) { + return; + } +#endif + Node *node = get_spawn_node(); + if (node && node->is_connected("child_entered_tree", callable_mp(this, &MultiplayerSpawner::_node_added))) { + node->disconnect("child_entered_tree", callable_mp(this, &MultiplayerSpawner::_node_added)); + } } Vector<String> MultiplayerSpawner::_get_spawnable_scenes() const { |