Behavior tree....odd behavior

I have a BT that’s behaving quite oddly.

The flow is always going to the right side, even if the condition on the left is met.
I can say it is met because the on-screen debugging blackboard states that there is a pawn in that variable.

This is the “FollowLeader” task:

Can somebody help me and explain me what’s happening?
Thank you

First: Better use a State System for this. Make an Enumeration that you change when the AI should do something else. Make the Blackboard Values of the Selector only look for the current State!

Second: I guess you first condition is still valid, since the TargetLocation is also set. AND as long as “MoveTo” isn’t finished, he won’t change the selected Node at all (at least i think that it was something like that).

Hello, thank you for your help, could you please elaborate more about the state system? is this a common solution? why is it preferable instead of a bt?

About the second suggestion i didn’ understand :frowning: should i interrupt the movement somehow to “break” the right branch loop ?
thank you

For the moveto, yes, there should be a function like stop movement. You can call this from the AI controller.

For the state system: You don’t replace the BT with it, you use it in the behavoir tree. Make an emun with entries like “idle”, “searching”,“following” etc. And for the blackboard condition you use this and check if the state is equal to whatever you want. When the player is in the follow state, the right tree is used until an event in this tree sets the state to searching or idle. Then the BTree will use the subtree with the other condition. Similar to what you are doing but only with a state enum instead of asking if something is set or not.

ok i understood the solution you are proposing, i am trying it now. thank you again.

Just for learning purpose, is there a way to effectively check if this wrong bt is caused by the movement or other causes?
Because i’d suspect that if i changed the “move to” with a wait node, the problem would remain; that makes me think that the reasoning that led me to this BT is somehow wrong, so i’m missing something

Uff, i’m not that into BTs. I know how to setup a basic AI but i have not idea if you use it correctly at this time. I only know that my BT stucked in a move to, because it would only change if it reaches the target or someone tells him to stop.

First of all I’d say your Task_FollowLeader has a bug, but you don’t need a custom task for what you’re doing anyway.

The bug is that you call Finish Execute just after requesting a move. Simple Move to Location is not a latent node, and it finishes after requesting the move, not when the move actually finishes.

The generic Move To BT task does exactly what you want (as far as I can read it from the Task_FollowLeader blueprint) so use that instead.

Regarding the “why” this doesn’t work for you, I’d guess the reason is that you’re storing a Pawn reference in your blackboard, but try to cast it to a Controller, which obviously fails. Now you do have a node to print stuff to the screen then cast fails, but I’m afraid that if you’re using Gameplay Debugger (the “on screen” AI debugging tool) then the regular Print String calls fail to draw. It’s a know bug. Confirm what I’m saying by putting breakpoints in your BP.

Cheers,

–mieszko

Thank you!
You are right: i never noticed the wrong cast.

What’s the correct approach to this ? object → cast to actor → getAIController ?

By The way, just editing the cast made it work, with the “Simple Move To Actor” at the end of the blueprint.

Thank you guys!

In this case you just need Object -> Pawn cast.