0 votes

Hi I try to make a method globally that queue free the enemy and/or player when the life it's 0. Problem is that i use an animated sprite with an area2d for player and enemies my script beeing attached to the sprite. The method is this:


func die(area):

but when the ememy need to die i get this:

Attempt to call function 'queue_free' in base 'null instance' on a
null instance.

what I'm thinking is that area is just null or it became null after they collide but I don't know how to take a reference of what hits the enemy? Any idea

Godot version v3.2.3 stable.official
in Engine by (48 points)

1 Answer

0 votes

That error means you are trying to delete something that doesnt exist, first of all check if you referenced it correctly (Wrong location or maybe a typo are the most common)

If the code is "correct", then check if that node is not being deleted before by something else.

Still, it seems like we're missing a lot of code to reach the cause... For example, where does this "area" var come from in the die(area) function?

By the way, to avoid problems, the player's root node should be a KinematicBody or RigidBody not an AnimatedSprite

by (309 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.