0 votes

I instance Bullets. Then I want that a enemy prints HIT if a bullet hits him. This I want to do with

func _on_Area2d_body_entered(body):
         if body.get_name == "Bullet"

But the problem is, that the name of the Instanced Bullet is something like @[email protected] and not just Bullet. How can I fix that?

in Engine by (378 points)

1 Answer

+1 vote
Best answer

A better way to do this is to use groups. When you create a bullet, add it to a group called bullets by doing something like:


or by having the add_to_group("bullets") line in the _ready() function of the bullets script.

Then change your code to something like

func _on_Area2d_body_entered(body):
     if body.is_in_group("bullets"):

You can read more about groups here:

by (449 points)
selected by

Thank you very much!

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.