How to change scenes and then be able to go back to previous

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Guiguis_Galdis

I am making a dungeon crawler and when the player changes levels, a new scene is loaded and a new instance of the playr is created. All the player’s information are stored on global script, when I try to go back to a previous level, I get this error:

Invalid type in function ‘add_child’ in base ‘Node2D (Game.gd)’. The Object-derived class of argument 1 (previously freed instance) is not a subclass of the expected argument class.

Can someone explain?

:bust_in_silhouette: Reply From: 1shevelov

Well, I’m not sure about exact reason for this error. If that scene was instanced without errors for the first time and freed later, I can’t see why it can’t be instanced again.
You can try another approach: do not delete previous scene, but hide() it, and show() when player returns