0 votes

So I'm have a conditional statement that looks like this:
if movetarget && movetarget.isingroup("player"):

movetarget is a variable and can be null when there is no target, that is what the first part of the condition is for, since it will only check "movetarget.isingroup("player")" when move_target is not null.

However occationally I'll get the error:
"Attempt to call function "isingroup" in base "previously freed instance" on a null instance."
What exactly does this mean? Is it when the node "movetarget" has just gotten "freed" by queuefree()? And it that case isn't that essentially equivelant to null and shouldn't be return false from "if move_target"?
Am I misunderstanding this completely or am I right but there is a reason it returns true.

in Engine by (70 points)

2 Answers

0 votes

Be aware that there's difference in queuefree() and free(). That's very tricky. queuefree() doesn't really free a node, indeed in some way it removes the node, but the value of the node will not be null, it still exsits in your program, but is labeled as a freed instance. Try use the function free() instead(Rember not to call free() when a method is still running. For example, ////func die(): ........... free()//// wrong. Use this instead/////func die(): ........ calldeferred("free")/////)
Edit: Sorry above is wrong in some ways. Seems that queue_free() instance will be a null object.

func die(): 
by (809 points)
edited by
+2 votes

I would not recommend using free(). queue_free() does in fact remove the node, just not immediately. (it waits until it is safe to do so).


if (move_target
    and weakref(move_target).get_ref()
    and move_target.is_in_group("player"):

    # do whatever

weakref(move_target).get_ref() checks to see if the node has been freed yet or not

by (1,612 points)

Edit:weakref(move_target).get_ref() tried this, returning null for both, interesting. I got problems when using queue_free(). Still it's confusing for me to have free() if they do the same thing while queue_free() is simply safer.

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.