How would I go about handling a large amount of weapon animations without cluttering the BlendTree with a lot of states and variables?
Going into a bit more detail, I am making a rogue-lite third person shooter, which in turn means I’ll have to have quite a few weapons as to not make the game super repetitive. While I don’t have a problem with making a modular weapon system to help with the process of making the weapons, I do have a problem with making the animations. Coming off of Roblox, it’s animation system was super simple, you just load an animation onto a character and which ever animation was played the latest will be the one layered on top of the other animations, animating only the keyframed bones.
Currently my character is set up in a simple BlendTree:
This BlendTree is as far as my knowledge of Godot’s animations goes, pretty much. I’ve tried messing around with StateMachine’s but that was difficult to manage for my character and I find BlendTree’s a lot more intuitive.
Since I want (or at the very least hope) my weapon animations to work in a way, where the weapons can have a different amount of animations, for example guns can have idle, reload, shoot, charge, ect. and melee can have different attacks and so on.
The best way I could visualize the imagined system is this:
The state machine serves as the “animation logic” where the weapon script would control which animations to play and the BlendTree would simply blend the required animations into the core character animations.
Also, since I had this problem when asking help outside of the forums:
I DO NOT have a problem with animating the weapon itself, my problem is animating the character.
An AnimationTree is a node tree that you can traverse and change at runtime. So you can also grab a ref to the “Animation” node and change the animation.
var animation_tree: AnimationTree = $AnimationTree
var animation_tree_root_node: AnimationRootNode = animation_tree.tree_root
var animation_node: AnimationNodeAnimation = animation_tree_root_node.get_node("Animation")
animation_node.set_animation("new_animation_name")
This way you only need a single Animation node and you just swap in whatever animation makes sense, e.g. equip a weapon, swap from unarmed animation to weapon animation.
But how would I go about blending the animation with the core character animations? Not to mention I don’t even use AnimationRootNode or AnimationNodeAnimation for my animations and instead use AnimaionNodeBlendTree
Those are the internal node names for the objects that you have in your screenshots and how you find them in the documentation.
E.g. the “Animation” node is an AnimationNodeAnimation node object inside the blend tree while the root in your case is an AnimationNodeBlendTree which inherits from AnimationRootNode.
For blending your character animation you would use the regular blendspace or transition or blend nodes. They all follow the same logic, e.g. a BlendSpace has animations stored at specific positions, so you can apply the same as in the example and swap animations in all other nodes to avoid having an entire set of nodes just for a specific weapon type or 100+ animation nodes for oneshot animations like emotes.
Does a similar thing of changing animations for Animation node work for the BlendTree node? Like changing the entire secondary (weapon) BlendTree for each weapon?
Do you know how I could achieve changing the weapon BlendTree at run time?
Since there doesn’t seem to be a BlendTree variable type.
I tried making a AnimationNodeBlendTree resource, but I seem to not be able to edit it separately from an AnimationTree node.
Look at the “AnimationNodeBlendTree” documentation that has all the functions.
The basic gist is you disconnect the old node from whatever input it is connected and remove it from the parent. Then you load or create the replacement, add it to the parent and connect again.
Ah, got it working!
All is left is to make a BlendTree and AnimationLibrary at runtime.
Should be simple enough following the doc’s functions for both.
Tysm for the help!