exporting child property of a scene (sprite_fames) and preview in editor the "correct" way?

Godot Version



my setup is a scene, consisting of a tilemap and many units (enemys):

since i use muliple units that behave the same way, unit is a scene that gets instantiated for every unit:

unit simplified:
+unit (root) - Node2d
±Sprite (animatedsprite2d)

in the editor im setting the properties like health, damage etc.
now i want to change the the sprite of my unit, but i also want to see the sprite in the 2d editor.

so i wrote:

class_name Unit


@export var sprite_frames: SpriteFrames :
		%Sprite.sprite_frames = value
		return %Sprite.sprite_frames


func _physics_process(delta):
	if Engine.is_editor_hint():

setting sprite_frames in the inspector will change the sprite. So i get the result it want, but im unhappy about the use of @tool inside my unit script.

i wonder how you other people solved this or how could i encapsulate the tool part into a separate script?

Everything there looks correct. You have to specify in the tool what frames the inspector is looking for. And, the maximum amount of frames the inspector is referring to. Usually there’s just a loop.

There’s a big discussion on the internet how to deal with Infinity. I say drag length, infinity.

I found out about inherited scenes.
It fits my needs without the use of tool scripts and i like that I can drag and drop unit presets.