How to activate animation state from a task in behavior tree

I have a behavior tree setup with a task to chase the player when he is within a certain distance. I have the state machine setup with variables for the transition. My requirement is to trigger the animation when the character starts chasing. I want to set the animation variable from the task in behavior tree.
Also, I can’t change the default pawn class to my desired character because I’ve already set it to a different character (followed the basic animation tutorials). It’s a non-humanoid model, so I’m setting up a different state machine. How can I set the animation state from the task?

Animation state transitions are based on variables of that give animation blueprint. What you need to do is introduce a new variable to your animation BP, that you’ll be setting in your animation BP’s update based on something (whatever you want) set in your pawn. And set that something from within your BT task.

Let me know if I’ve lost you there :slight_smile:



Ok, here’s an update of what I did. I have created a variable in my animation blueprint and used that variable for the transition. Now, how do I go about changing this variable in animation bp from inside the BT task? Or should I pass it to the character bp first and access that from animation bp?

Yeah, it needs to go through the character.

I wasn’t able to set the variable in character bp from task. I believe I’m able to get the animation working using the variable in character bp.
I created variables in my character bp. From animation bp, I access these variables by casting.

So, when I change the default value of the variable in my character bp, the update is reflected in viewport.

I can’t find a way to set the variable in character blueprint from task. Could you please help me with it?

I wasn’t able to set the variable in character bp from task

Would you mind elaborating? What was wrong? Why weren’t you able?

I tried casting to my character BP and set the variable.


Unfortunately you cut out information on what you’re casting, but I can guess what’s wrong. The actor you get as part of BT event calls is in case of AI the AIController driving the character. You need to cast that to AICharacter and then call GetControlledPawn - this will retrieve you something “castable” to your AI_Character. Or you can use the AI-specific BT events, like ReceiveExecuteAI.

Apologies for the lack of information. I was casting on the bt task itself.

Ummm. What? :smiley: How? Where?

Did you implement your own BT task in blueprints? If so the way it works is you need to implement some of the events that come along with it. And the controlled entity is one of the parameters of said events. Would you mind giving more details about your setup?

I’m working on a modified version of the blueprints of the first person example project(from online unreal tutorials).
Here’s my behavior tree.

I’ve replaced the chasing player with a different model and it’s animations for which I created a animation blueprint and state machine.
I’m not sure what you mean by setup, but please let me know if you need any more info. I’m a beginner in unreal. :slight_smile:

It works. I followed your method of casting to the ai controller. It works now. Thanks a lot.

can you post your animation BP, especially the part the shows your task for attack