0 votes

I call this code when the player leaves a collision body:

    if dialoguebar != null:
    dialoguebar.queue_free()

If the player walks back into that body, then walks out, I get the error in the title:Attempt to Call Function "Queue_Free" in base 'previously freed instance' on a null instance
Why does this happen? Shouldn't the if statement check if the dialoguebar exists and not call queue_free if it doesn't? Am I doing something wrong here?

Thanks in advance!

in Engine by (47 points)

1 Answer

+1 vote
Best answer

The instance may have been fred, but that doesn't mean it contains a null. In fact, you should ask if the instance is valid. The objecto won't convert to null because its resources being freed. You could try this"

if dialoguebar != null and is_instance_valid(dialoguebar):
    dialoguebar.queue_free()
by (3,394 points)
selected by

Thankyou! Replacing the dialoguebar != null with is_instance_valid(dialoguebar) seems to have solved this problem :)

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 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 webmaster@godotengine.org with your username.