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

Godot Version

4.2.2

Question

Hi,
my setup is a scene, consisting of a tilemap and many units (enemys):
+battlescene
±tilemap
±units
-±unita
-±unitb
-±unitc

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)
±statemachine
±manymorenodes

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:

@tool
class_name Unit

#code

@export var sprite_frames: SpriteFrames :
	set(value):
		%Sprite.sprite_frames = value
	get:
		return %Sprite.sprite_frames

#code

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

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.