Name of Instanced Bullets

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

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 @Bullet@17 and not just Bullet. How can I fix that?

:bust_in_silhouette: Reply From: denxi

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:

Thank you very much!

Godot_Starter | 2020-03-01 19:18