Access a class instance from inside a behavior tree

I’ve been learning how to use Behavior trees recently. I’ve done the tutorials on UE’s website but I’m running into some issues when I try to expand upon it. Basicly, I have a Behavior tree with a blackboard. On each cycle, i want to get a variable of type BasicAICharacter (inherit from character) to update my blackboard. I’m doing so with a service (see screenshot).

The object the behavior tree is run from is itself a BasicAICharacter. However, I cannot just cast the owner Actor into a BasicAICharacter. It seems I also cannot have a variabler of type BasicAICharacter in my blackboard.

How Can I refer to the BasicAICharacter from inside the service of my behavior tree ?

check if the character who is running this behavior is from BasicAICharacter, i’m pretty sure you can cast it correctly to the class if the behavior belong to that character.

My BasicAICharacter has BasicAIController as default AI

and the behaviour tree is called from BasicAIController.

Could it be because the one starting to run the behaviour tree is actually the BasicAIController and not BasicAICharacter ?

If so, How can I reference my BasicAICharacter from the Behavior Tree ?

The Owner Actor you get as part of Execute Receive Tick call is the AI controller of your character, so you first need to cast it to AIController, then call Get Controlled Pawn and cast it to your BaseAICharacter.

To reduce number of casts needed I’ve introduced alternative, AI-centric events to BT nodes so that you’ll get AIController and Pawn right off the bat. This will be available in 4.7 and is already available in github promoted build.

Cheers,

–mieszko

1 Like

Thank you for the explanation and quick answer. I have to learn UE under fairly tight time constraints and this is greatly appreciated.