+1 vote

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():

but this prints something like @[email protected] rather than howdy (the name I set)

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

in Engine by (29 points)

1 Answer

+1 vote
Best answer

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.

by (21,979 points)
selected by

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

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.