Whats the best way to communicate between the character, behaviour tree and the animation blueprint?

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.

  • I’m then using a decorator to trigger a task off the back of that tell the character to approach the player.
  • Then when the character is close enough to the player, I’m setting a bool in the animation blueprint to tell it attack.

302381-animationblueprint.png

  • Then the animation blueprint is playing the animation and using a notifier on the animation combined with a sphere trace.
  • That notifier would then tell the character that it’s been hit.

This might be the best way of doing it but it seems very convoluted.

So it effectively works as:

Character → Behaviour tree - > Animation blueprint

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.