Name with add_child script not same with original name

Godot Version

4.2

Question

guys, I’m still learning and want to spawn a scene that I’ve created with the add_child script, but the spawned name is not the same as the original name. I want to organize the names like laser, laser2, laser 3 but the result is area2d 2, area2d 3… how can I do that?

A node is given a random name when it is instantiated at runtime.

If you want it to have specific names, then give it specific names. You didn’t provide any code, so I assume:

var laser = laser_scene.instantiate()
add_child(laser)
laser.name = "MyLaser4" # give it a name here
laser.position = Vector2(42, 69)

The given name must be unique per siblings.

2 Likes

Yeahh!! it works thanks :slight_smile:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.