summaryrefslogtreecommitdiffstats
path: root/modules/multiplayer/scene_replication_interface.cpp
diff options
context:
space:
mode:
authorFabio Alessandrelli <fabio.alessandrelli@gmail.com>2024-01-14 20:09:58 +0100
committerFabio Alessandrelli <fabio.alessandrelli@gmail.com>2024-01-14 20:54:41 +0100
commitcb08f2a9689eff85256e020608ac264bcdaf57f7 (patch)
tree5e093d3db7d10cab37ab0286b435a7463d9e42a4 /modules/multiplayer/scene_replication_interface.cpp
parent26b1fd0d842fa3c2f090ead47e8ea7cd2d6515e1 (diff)
downloadredot-engine-cb08f2a9689eff85256e020608ac264bcdaf57f7.tar.gz
[MP] Fix spawned nodes not working after reset
Ensures that spawnable nodes (i.e. spawned nodes over which the local instance has authority) always have a network ID, since they may lose it after the multiplayer is reset (e.g. when changing the multiplayer peer).
Diffstat (limited to 'modules/multiplayer/scene_replication_interface.cpp')
-rw-r--r--modules/multiplayer/scene_replication_interface.cpp9
1 files changed, 5 insertions, 4 deletions
diff --git a/modules/multiplayer/scene_replication_interface.cpp b/modules/multiplayer/scene_replication_interface.cpp
index 31307e648d..c3d239e4b7 100644
--- a/modules/multiplayer/scene_replication_interface.cpp
+++ b/modules/multiplayer/scene_replication_interface.cpp
@@ -189,9 +189,6 @@ void SceneReplicationInterface::_node_ready(const ObjectID &p_oid) {
spawned_nodes.insert(oid);
if (_has_authority(spawner)) {
- if (tobj.net_id == 0) {
- tobj.net_id = ++last_net_id;
- }
_update_spawn_visibility(0, oid);
}
}
@@ -472,9 +469,13 @@ Error SceneReplicationInterface::_make_spawn_packet(Node *p_node, MultiplayerSpa
ERR_FAIL_COND_V(!multiplayer || !p_node || !p_spawner, ERR_BUG);
const ObjectID oid = p_node->get_instance_id();
- const TrackedNode *tnode = tracked_nodes.getptr(oid);
+ TrackedNode *tnode = tracked_nodes.getptr(oid);
ERR_FAIL_NULL_V(tnode, ERR_INVALID_PARAMETER);
+ if (tnode->net_id == 0) {
+ // Ensure the node has an ID.
+ tnode->net_id = ++last_net_id;
+ }
uint32_t nid = tnode->net_id;
ERR_FAIL_COND_V(!nid, ERR_UNCONFIGURED);