How to Cast to AITree from AnimBP?

Any help? From my AnimBP, figure out if AITree is playing a certain MoveTo?

i.e. I don’t want to cast to MyCharacter then AnimBP

Hello,

I am trying to tell my AnimBP that the AITree is playing a certain MoveTo.

I DO NOT want to cast inside anything but the AnimBP because I want to use the AITree and all its Tasks/Services for all my AI.

Therefore, I want in each specific AI’s AnimBP to communicate with the AITree (Or Tasks/Services if communicating with the AITree specifically is impossible) so that the AI Controller, AITree, Tasks and Services remain free of CastTo Nodes.

Thanks.

I wouldn’t recommend accessing the AI Behavior Tree from the Animation Blueprint, it seems somewhat hacky to me and not Object Oriented. If you want your AnimBP to know something about your Behavior Tree then expose this data through your AI Pawn/Character blueprint which is the one that usually communicates with the AnimBP. For example you could create an enumeration for state variable on your AI Pawn/Character blueprint that gets set only inside the Behavior Tree and you would access and read this variable inside your AnimBP.

This way your AnimBP does not know anything about your Behavior Tree and your Behavior Tree does not know anything about your AnimBP since your AI Pawn/Character blueprint is acting as the mediator.

I am setting an enum inside a BTService that is attached to a selector in my AITree. How can I take this enum state (idle, attack) to share it with AnimBP or characterBP?

Can you show me how to take enum and then set myChatacyerBP variable with it?

Ok.

Assume I have these classes (Basic stuff for having an AI)

114237-ai.png

Now on my AI_Character class I would a variable of type AI_State and that’s it.

I would then also have a variable of type AI_State inside my blackboard (I made this behavior tree just as an example). I would have an Update State Service. Know that you can set your state or any other blackboard variable or character variable in any task or service but I like to delegate that chore to only one service if possible.

The inside of the update state depends on how your AI is supposed to behave. I just made it so it sets the state variable in the character but in reality it should change the blackboard state depending on whatever you want and THEN set the character state variable so they always have the same value.

After that, in your AnimBP you can just read the state variable from the character that should mirror the state variable inside your Behavior Tree/Blackboard

So at the end what you achieve is something like this:

114252-ai4.png

Where your AnimBP knows nothing about your Behavior Tree / Blackboard implementation so if you wanted you could replace your Behavior Tree class with another one and the only condition is that at some point it sets the state variable on the character so the AnimBP can read it and know about it which is obvious. This way they are decoupled

Hi, I am just reading this and checking with my project, but
AI_Character class variable of type AI_State is an enumeration var?

I do have all 7 items in my content folder, and that is it (I am using BTService).

yup!

Hey! It works! I was trying to do a branch enum == and set the variable right in the AnimBP, or CharacterBP, but by not having a specific enum variable it did not work with bools.

Thanks a lot…is there anyway I can still have different AI_Characters run the same setup? Or am I at a loss here? Their animations just change based on what state it is inside the enum…but I am casting to the AI_Character BP specifically…can I do this through the AI_Controller or something similar?

yes, you could for example create blueprint child classes from your AI_Character so they can have different implementations for whatever you want but they will all have a state variable that your AnimBP will be able to read

Edit: About the enum not being specific. Basically all enums are bytes so when you have a “not specific enum” you can cast it to your type of enum. Just drag the pin for this enum and on the search box type the name of your enum, it will say something like Enum to YourtypeOfEnum. It’s exactly what I did here:

114257-ai5.png

That black box node is casting from a not specific enum (just byte) to my AI_State enum

Awesome, thanks! So specific and right to the point.

I will use child blueprints of my CharacterBP so I can use different AnimBP’s (thus different values to set based on enum options inside each AnimBP).

Cheers!