Godot Version
Godot Engine v4.3
Question
So basically I have a script which extends from a GridContainer that sequentially adds 64 ColorRects as children to form an 8 by 8 grid. The result looks like this:
The problem is that when I try to access the global position of each ColorRect after it’s been added as a child, each ColorRect believes that its global position is the same as the parent GridContainer, i.e. if GridContainer global position is Vector2(-256, -256), then each child’s global position will also be Vector2(-256, -256). Is there a way to prevent the ColorRects from inheriting the GridContainer’s global position? Here is my code:
extends GridContainer
const TILE = preload("res://tile.tscn") # Tile is a class inheriting from ColorRect
func _ready() -> void:
const TILE_COUNT: int = 64
for tile: int in range(TILE_COUNT):
var new_tile: Tile = TILE.instantiate()
add_child(new_tile)
print(new_tile.global_position)