I'm building a platformer where when the player dies, a new one respawns, leaving the old player where it died. After a certain number deaths, the player is kicked out to the main menu and must restart the level. This worked fine, until I quickly clicked the button to reload the level after dying, and all the old players were there.
When the player loses, this function is called:
get_tree().reload_current_scene() # My attempt to get all the nodes to reset. Makes no noticeable difference
get_tree().change_scene("res://Scenes/MainMenu.tscn") # After saving, load the main menu scene
When the button to load the level is pressed, this function is called:
If I wait a few seconds before hitting the level load button, all the instantiated nodes are removed, and the scene goes back to its default state, as expected. It's only when I quickly reload the level that the instantiated nodes are preserved.
Is this something I'm doing wrong with loading/unloading scenes, or is this a bug in the engine?