stuck at attack in behavior tree

i have a behavior tree running for my horse, now i setup in the behavior tree to chase a target if target is set, and to attack it if in attack range, now i have an issue where the behavior tree is stuck at attacking the moment the target is set, even if its not in range it just stuck at attack when i changed the aborts to “both” for “TargetIsSet” and “DistanceToTarget”. i played with the aborts and sometimes the horse chases the target first, but when it reaches it, it starts attacking but stays stuck at it even if the target leaves the range. how to fix this issue, iam not that experienced in behavior trees.

This is my behavior tree

This is the CheckDistance service

And this is the attack task

Hey!
Generally speaking you should always use the GameplayDebugger to check the state of your AI and its BT Tasks.

Also just a hint to avoid weird issues like yours, in your Event Receive Execute AI function of your BT Task, make sure to also call Finish Execute when your cast node fails (but return Success = false)

Setting your blackboard conditions (TargetActor is set and Distance Check) to abort both itself and lower priority tasks is good as well.

For further help, could you verify if it actually is the BTTask_HorseAttack that seems to be stuck?
Also does it just execute over and over again or is it stuck in just one execution and never finishes (check what I said above) ?

so what actually happens is it keeps executing over and over again in the behavior tree. and not the attack task itself, and incase i added the finishes execute = false for cast failed node. but still same issue, so its the behavior tree casting the attack none stop

Can you verify that the distance is correct and thus technically should make your distance check fail?

okay so i checked the distance, and for some reason its always 0, it never changes

And you did assign the proper TargetActor and DistanceToTarget Keys?

Note: Also you might want to use the inbuilt “distance” node instead of manually subtracting and getting the length of the result.

okay so i fixed it, my problem was i wasnt actually assigning it in the behavior tree. i didnt set them to editable so i can change it. its crazy how i wasted 3 hours trying multiple stuff while the issue was simple XD. thank you for opening my eyes to look at simple stuff <3

image

there is another thing bugging me, i have in the enemies a boolean for “is dead” but how do i actually make the horse see that the enemy “is dead” without having it to wait until the actor is destroyed.

Well the way how you would implement something like this depends a lot on your skills in ue.

Usually what games would do is implement a custom sight affiliation filter that makes the enemy “visible” to the ai only under certain conditions (aka being alive, etc).

I assume (non-personal) that, since you said you’re pretty new to BTs, you would prefer a simpler solution :grinning_face: .
Also I would need to know more about how your AI logic is currently setup .

Either way, I would recommend you to check whether your enemy is alive every time your AI “sees” a new target and add another service in your BT that checks if the enemy is dead and then clears your TargetEnemy key.
Its not ideal but by far the most simple way.

understood, i will be trying that. Thank you!

You’re welcome!

(for my forum stats, would you actually mind marking my comment (instead of yours) as the solution?
That would help me a lot getting a better rating :grinning_face_with_smiling_eyes: )

no worries

thank you, I appreciate it! :grinning_face_with_smiling_eyes: