0 votes


For a while I have been struggling with my game crashing randomly when I try to check if a node is in a scene. I have tried to explain my issue, but as I am new to Godot, I seldom understand what people mean and I am unsure how to apply their answer to my problem.

I asked this question: https://godotengine.org/qa/33722/avoid-getting-invalid-index-previously-freed-instance-error

I have uploaded my project, so you can see what I mean when I describe my issue: https://ufile.io/aa7ic

My issue
Junk spawns randomly and the crabs can pick it up. When they drop it in the bins, the junk is deleted. Sometimes the game crashes, because it tries to run the code, where the crabs carry the junk after they dropped it. I test if the crab is carrying the junk by saying if carried_object: before manipulating the node. However, sometimes (and I have not found a pattern) it ignores the fact, that I check if the node exists and still tired to update its position. I tried to print out the node and at the moment it crashes, carried_object is called [Deleted Node]. This is driving me crazy as I cannot find anything online about it. If you have a suggestion, I would be very happy to receive it.

Thanks a lot! :-)

in Engine by (24 points)

1 Answer

+1 vote

Can you link the code, it is hard to tell what you are doing. There are multiple reasons this could be happening.

Are you using queue_free() to delete the object?

Also instead of if carried_object: try if carried_object != null and if carried_object != [Deleted Node] :

by (1,488 points)

Here are the scripts that manipulate the nodes:

https://pastebin.com/RESR938R - bin.gd - deletes the nodes
https://pastebin.com/wv6T2b0A - helper.gd - uses the nodes and drops them in the bin

I use queue_free() when deleting the nodes and I have tried carried_object != null which did not work and carried_object == [Deleted Object] is not of valid syntax.
(it was [Deleted Object], not node, I remembered wrong)

I have read about the has_node("node") function and would try to use that. But how would I get the path string fromcarried_object?

Thanks for your help!

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.