How can I deleted permanently a node?

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

Hello, I want to delete some nodes after they were used. I tried queue_free() and remove_child(), but when I change to a new map and come back to the old map, the nodes still there.

:bust_in_silhouette: Reply From: rakkarage

sorry didn’t finish reading :slight_smile: there is also a free without queue

:bust_in_silhouette: Reply From: Sakaki

As far as I understood you want to maintain some level of persistence between your scenes. The thing is, when you load a PackedScene from the file system, e.g. get_tree().change_scene("path/to/scene.tscn") Godot will load the scene as saved in this file, resetting any changes made during the playthrough.

One way you can achieve what you want is to repack the scene and either keep it in memory and switch to it during the play session, but you will lose the changes when you close the game, or you can save it on disk and load it from there. You can save it in the user:// path.

const SAVED_SCENE_PATH = "user://path/to/saved_scene.tscn"
const DEFAULT_SCENE_PATH = "res://path/to/scene.tscn"

func some_func():
    if ResourceLoader.exists(SAVED_SCENE_PATH):

But if I fight a monster in the previous map and dont wanna fight it again when I come back to this map, how can I do that?

DarlesLSF | 2020-07-21 15:58

I just told you, you have to save the current state of the scene and load it again when you come back.

You can do it using PackedScene.pack(node) where node is the root of your scene. Then you can save it on disk with, "path/to/saved_scene.tscn"

Sakaki | 2020-07-21 16:55