Why is child scene being put at global position?

Godot Version

4.4.1

Question

I have a room generation script that spawns a room. The room has a Enemies node that holds 3 Enemy scenes. These are placed by hand, and not through code. The room gen script instantiates the room, then places it at some global coordinate. When I run the game, the enemies are all stacked onto the same spots in the global area.

Here is the room scene code:
func place_room_at_xy(coords:Vector4,center:Vector2):
var tile_offset = Globals.room_size * Globals.tile_size

var newRoom:Node2D

for i in range(0,len(roomsack)):
    var tempRoom:Node2D = roomsack[i].instantiate()
    if tempRoom.get_exit_type() == coords.z:
        if tempRoom.get_room_rotation() == coords.w:
            newRoom = tempRoom

var adjusted_coords:Vector2 = Vector2(coords.x,coords.y)
adjusted_coords -= center
adjusted_coords *= tile_offset
adjusted_coords.y *= -1

add_child(newRoom)
newRoom.global_position = adjusted_coords


Replace the Node parent of enemies with Node2D.

1 Like

Thank YOU!!!

1 Like

The answer was replace the node parent with Node2D. Because someone might stumble on this, and not really understand how this works:

The WHY is, because regular nodes don’t have a Transform - forcing their children to always be positioned relative to the global 0:0 coordinates.

2 Likes