Queue Free Single Player inventory

Godot Version 4

Hopefully this is simple -

In my game I have it where the player can collect gems - though it seems that when I collect them and then die to an enemy, the player does the die animation but does not ‘self.queue_free()’ and return to the main screen scene. I have tried to do just ‘queue_free()’ to see if that would get rid of the gems, but ran into the same issue. It does not pop up as an error in the debugger either.

Is there a simple way to code to remove items from a players inventory?

Thank you for your help!!

Can you share some more code with your dying logic and inventory logic?

Do you want to queue free the whole player, or the inventory, or just the collected items from the inventory?

1 Like

Hey @wchc, I’m jumping in since I’ve faced a similar issue. If the player or inventory holds references to objects (like collected items), queue free() might not work as expected because those references can prevent proper cleanup. In my case, I had to manually clear the inventory data before calling queue free() on the player. It seems Godot 4 handles node lifecycles a bit differently, so cleaning up explicitly can help avoid lingering issues.

1 Like

Im guessing you stored them in an array, you can simply use the method clear() , e.g inventory.clear()

1 Like

This is my knights dying code:

I don’t have a complete inventory system as of yet - mostly just a counter. which is like this in the knights code:

I have the gem variable at the top and then the amount at the bottom.
It could be another issue entirely I’m not 100% - I’m just running out of ideas on why he won’t return to the main scene

So you want to reinstatiate the game scene after dying.
I think you can completely skip the queue_free lines and go straight to the change_scene line after the animation stops playing. The Knight will be automatically removed and reinstatiated with the scene.
Can you try that?

Tried it and no dice - it does the same thing with or without queue_free - I took a video that might help show what is going on -