Preview selected AtlasTexture in scene view

Godot Version

4.5

Question

I have instantiated child scenes. The instantiated child uses an AtlasTexture, Sprite2D, PathFollow2D etc. I have an exported Enum (Red, Blue, etc.) to setup the atlas region that maps a value as an offset in said atlas. I set the region in _ready() but in the scene view always the initial region (color) is displayed. When in game the correct color is rendered/selected.

How can I preview the selected atlas region in the parent scene? Or any other property like flip_h of the sprite?

enum Army {GREY = 0,GREEN = 16,BLUE = 32,RED = 48,ORANGE = 64}

@export var army : Army = Army.GREY

func _update_sprite_atlas():
	var atlas = _sprite.texture as AtlasTexture
	atlas.region.position.y += army

You’ll need to make the script a @tool script

Ah that works but comes with a few caveats. For clarification if anyone finds this post:

  1. Make the whole inheritance tree @tool script
  2. Be wary of static variables and function.
  3. Do not rely on globals