How can I queue_free an object that's not actually added to my current scene?

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

I’m working on a Dwarf-Fortress type game that goes through a proc-gen world creation before you play.

It creates npc’s , items etc.
The npc’s are instance of a Being scene.
The items are resources, not actual scenes.

In the world creation scene - I create the instances, but I don’t actually add them to the scene, I just put them in a list so I can loop through them.

As the world creation loops - I’ve found it’s not safe for me to be queue_free-ing these in my main loop… so I add them to a list in autoload called: “gamelistofobjectstoqueuefree”.

When it’s more safe to do so… I then loop through the Autoload.gamelistofobjectstoqueuefree list, and try to queue_free each item in the list.
But I get error : " Attempt to call function ‘queue_free’ in base ‘null instance’ on a null instance. "

Any idea why I wouldn’t be able to queue_free from a list I’m keeping in an Autoload/Global/Singleton script?

Also - how do I handle the items, which are resources, not Scenes at all. Can I queue_free a resource?

:bust_in_silhouette: Reply From: klaas

Hi
the error tells you that there is no object referenced in the list. Maybe you want to make a breakpoint there and analyse the properties you are refereing to.

For the resources … godot resources are reference counted. That means if there is no more reference pointing to the object they automaticaly get released/deleted.

Marked as answer. I took a closer look. I was queue_free-ing just fine, after reading your response I went back and realized - I wasn’t also removing that object from the list, hence the error. Doh. Thanks for your help.

mattkw80 | 2021-08-17 16:09