How to get name of an instanced object?

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

Hello there! Can you help me, please?

I am trying to make possible for player to select an enemy in my 2D top-down game. Once the target is selected, the player should get its name. I’ve tried whats on the pictures below.

Everything is instanced in-game.

Used variables are:

  • cursor_area = Area2D node with child node RectangleShape2D called cursor_shape
  • possible_targets = an empty array
  • target_nameplate = Label node

In set_target() func, the rest of the line not shown on the picture is just the global_position of the cursor_area.

Now the thing is, it seems I can’t get the name of the target. print(target_name) is not printing anything and the target_nameplate is also showing nothing.