Get StaticBody2D name from Area2D overlap

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

I have a StaticBody2D that I create dynamically and set the name

var static_body = StaticBody2D.new()
static_body.name = 'howdy'

I get the name from an Area2D overlap

for body in get_overlapping_bodies():
  print(body.name)

but this prints something like @howdy@47 rather than howdy (the name I set)

How do I get and/or set the name correctly to get the same name I set?

:bust_in_silhouette: Reply From: kidscancode

Names must be unique among siblings. If you have multiple instances and they all have the same name, Godot will automatically name them using the scheme you are seeing.

One shouldn’t rely on node names for identification. Especially when instancing a large number of objects, it becomes cumbersome to track. The typical approach is to add the node to a group or otherwise tag with your own custom property.

Sounds good. I’ll look into groups, thanks!

MathiasStrohkirch | 2020-04-09 02:12