Attempt to Call Function "Queue_Free" in base 'previously freed instance' on a null instance, but why?

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

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

	if dialoguebar != null:

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!

:bust_in_silhouette: Reply From: p7f

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):

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

Aravash | 2020-07-02 22:43