0 votes

When the hero script receives signal body entered I want to delete the bullet which is instance. I tested now it's showing this Attempt to call function 'queue_free' in base 'previously freed instance' on a null instance.

func _on_Area2D_body_entered(body):
        if body.name == "zombiGirl":
            #print("zombi touched")

func delete_Magic():

someone told me I should use call deferred I don't know how to use it

Godot version 3.4.2
in Engine by (24 points)
edited by

1 Answer

0 votes

"Attempt to call function 'queue_free' in base 'previously freed instance " means the bullet has already been deleted. Is there some other place in the script where you delete it?

if magic_copy the bullet that you're trying to delete?
One simple fix is to just check
if is_instance_valid(magic_copy): magic_copy.queue_free()

call_deferred has the following syntax:
call_deferred("NameOfTheFunctionToCall", "ParameterToPassToTheFunction")
and what it does is it calls that function a bit later... like, after all the other code for that frame has been executed.

by (1,290 points)
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.