Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | sygi |
I’m trying to follow this tutorial on changing scenes in a multiplayer game. I have the following structure:
- world (Node3D)
- level (Node3D)
- actual_scene (custom)
- MultiplayerSpawner
The level has the following function:
func change_level(scene: PackedScene):
assert(get_child_count() == 1)
var current = get_child(0)
remove_child(current)
current.queue_free()
add_child(scene.instantiate())
When I call it only on the server, the server correctly removes the previous level and adds the new one, but the client only receives the new level from the multiplayer spawner but doesn’t remove the previous one, ending up with having both.
I tried to change the MultiplayerSpawner to use custom spawns by adding this code to the world:
func _ready():
$MultiplayerSpawner.spawn_function = $level.change_level
func change_scene(scene: PackedScene):
$MultiplayerSpawner.spawn(scene)
but then I got instantiate_custom: Failed to call spawn function.
and on_spawn_receive: Condition "!node" is true. Returning: ERR_UNAUTHORIZED
.
Any idea what I’m doing wrong and how do I remove the previous node while adding a new one?