Godot Version
4.6.3
Question
I’m trying to dynamically create a ColorRect as an aiming reticle. The ColorRect never appears on screen, and adding it causes my existing Sprite2D (a placeholder square for the player character) to change from solid gray to a black-and-white gradient.
aim_box = ColorRect.new()
aim_box.size = Vector2(80, 80)
aim_box.color = Color.RED
aim_box.z_index = 10
get_tree().current_scene.add_child(aim_box)
aim_box.position = global_position - aim_box.size / 2
In Godot 4.6.3 (2D project), when I create a ColorRect via script and add it to the current scene, the ColorRect never appears even though it exists at the correct position with a solid color. At the same time, an existing Sprite2D that was displaying a solid gray GradientTexture2D suddenly changes to a black-and-white gradient. I’ve tried setting z_index, changing colors, and adding to different parents, but the issue persists. What could cause a dynamically added ColorRect to be invisible and corrupt the texture of an unrelated Sprite2D?