Instances Ignoring Scene Changing

SO! I am using Godot 4 to make a game with Tetris-ish physics. It doesn’t really matter how the blocks work, but the important thing is the way the blocks spawn is by preloading them upon start and instancing them when I need them. When the player dies, I then switch scenes with get_tree().change_scene_to_file("res://scenes/game_over.tscn") to show the game over screen. The problem is, everything disappears except the blocks when this happens, even the thing instantiating them. They shouldn’t be there, but they persist. Can someone tell me how and why this is happening and how to solve it, or if there’s a better way to die?

After instantiating the blocks, where do you add them as child?

I use get_tree().get_root().add_child(block) to spawn them.

Ah, get_tree().get_root() returns the tree’s root window, which is outside of the current scene you’re changing. Try using this instead:

get_tree().current_scene.add_child(block)
1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.