I'm developing an RPG. I have 3D models with accompanying animations for all units/characters. Models and animations are made in Blender and exported as .glb.
I want to have an AnimationTree that can switch between these animations. These animations are standardized; every unit has a Run animation, Idle animation and so forth. I have a base class "Unit" that looks like this :
(UnitAnimation is an AnimationTree)
Since all Units have the same animations, I would like to create an AnimationTree blend tree graph that is generic and can be used by all Units, like this:
AnimationTrees require an AnimationPlayer to be able to add specific Animation-nodes to its node-graph ("Run", "Idle", etc). However, the AnimationPlayer for each 3D model with these animations exists in the glb-scene, and are thus added at a later stage when the Unit node is extended.
My solution (that is quite ugly):
In my UnitAnimation-node, I have a dummy AnimationPlayer with empty animations named "Run", "Idle", etc. I use this AnimationPlayer to create the blend tree graph.
When I add the glb, I make UnitAnimation target that node's AnimationPlayer instead. This works most of the time.
The big problem:
Some models don't have all animations; either because I haven't implemented them yet, or because that model wouldn't need it. That makes the AnimationTree stop working, since it cannot find all animations in its graph, even if those animations aren't used.
Ideally I'd like for the AnimationTree to play a default animation if it cannot find the specific one.
Questions:
1. Is there a better way to create a reusable AnimationTree, that also can account for missing animations?
2. Also, is it possible to create AnimationTree-graphs with code instead of visual programming?