Separating animations from scenes and scripts (using resources?)

Godot Version

4.3-stable

Question

I am working on a game that has lots of different units with very similar behaviour (imagine like, “team orcs”, “team goblins”, etc…), and options but that differ visually. So I have started using a resource to configure them. This has worked wonderfully so far for buildings (well, house, wall, etc…) and items (wood, metal, etc…).

However my units are proving more difficult, under the hood they are all identical, and each has it’s own set of animations (though all the same purposes and names. e.g. “walk”, “idle”, “carry”, etc…).

What I would like to do, is configure those animations into some sort of object on the unit resource, so the unit script can pick that object up and play the animation when required, allowing me to keep my unit code and scene generic.

With buildings - as they are not animated - I was able to do this as follow:

@export var Graphic: Texture2D

I was hoping to do something with my units like:

@export var animations: AnimationLibrary

But this either doesn’t solve the problem, or I can’t work out how to use this to load animations into.

If anyone has any advice they can share on separating the animations from the scene and script, I’d love to hear it!

Thank you.

I have continued looking into this topic, and it appears inherited scenes is what I was looking for, more info here: Inheritance in Godot 4 - Tutorial

I’m still interested in any other thoughts people might have around this though!