Hi I’m studying setting up of character and I’m a little unsure what the best practices are for communicating between the character, behaviour tree and the animation blueprints.
For example say I wanted to get the character to attack the player. At the moment I am doing this:
An event on the character to register when it see the player. I’m then setting a blackboard bool in the behaviour tree to say it’s seen the player.
Generally you will have some blueprint or C++ code that sets a target actor on the blackboard, and then the actor can conditionally run logic based on whether the target actor is set. A boolean is far less useful building logic aroung. The mere fact that the target actor is valid(and not null) also fills the role of a boolean based targeting mechanism.
For attack animations, typically you would play an animation montage or sequence on the mesh of the character, both of which you can attach notify events to in order to fire events, to signal to the game useful events that happen within the scope of the attack animation playing. Maybe a certain frame plays a sound or effect, or performs a collision query to detect and apply damage, etc.
See
Here’s my recommended approach for the BT, built around an Actor reference value in the Blackboard called Target
You can flesh out the tree above the HasTarget so there is a fallback behavior when they don’t have a target
You can do far more with an actor target reference than you can a boolean, and for attacking, you simply play an animation, and let any notify events trigger back any relevant data you need to be aware of.
Great thanks. Just one question, When playing animations directly in the behaviour tree, it loses a lot of the functionality of the animation blueprint. For example it snaps into the animation, I’m also not sure I can do things like selected just parts of the body to animate.
If you play a montage with the PlayAnimation task, the montage holds its own blend in values, and you can also configure the montage to play on different slots, which you set up prior to layer onto different parts of the body.
For example, in my animation blueprint, I have a state machine for basic locomotion pose, and then a full body montage override node, then an upper body montage override. Many of my attack animations just play on the upper body montage. slot.
From the perspective of the behavior tree though, it just plays the animations. The details for how it plays is wrapped in the montage asset.