Ways to destroy objects other than queue_free()

Every time I’ve wanted to destroy objects in my current project I always use
queue_free(). But this is creating some collateral effects where some objects will be permanentely gone after I return to their scenes. Is there another way to destroy objects without this side effect?

You could try adding a function called _destroy or something similar. In that function, you could hide the parent and disable the collisions. Then, in another function, you could do the opposite of that. Then, when you want to delete it, call the _destroy function. When you need to go back to the scene, you can the opposite function.

The other option (if you don’t need to maintain information) is to make everything its own scene and call queue free when you need to get rid of it. When you need it again, you can call scene.get_tree().reload_current_scene() (scene is the scene you queue freed).

I would go with the first option as it retains information (like variables), but the second one is easier.

1 Like

I’m pretty sure if you set something to null, it will be cleaned. But when that will happen is another story. I remember reading on this at some point.

That may or may not help you. That’s all I’ve got.

sounds like you just need to be setting visible to false if free() is not your desired outtcome