Leave Move To Location or Actor Task On Condition

I have a wander task in my behavior tree that uses Move To Location or Actor. I would like to be able to leave the task prematurely if the AI detects the player, but I haven’t been able to figure out how to do it yet. The aggro check task is higher up in the behavior tree than the wander task and executes every 0.5s but it seems like once execution gets into the wander task node it doesn’t leave until the move is complete.


You’ll want to use a Blackboard decorator on the sequence node for your wander behavior. I assume you have some key in your blackboard that says whether or not it should be following your player, use that as the “Blackboard Key” in the decorator and make sure that “Observer aborts” is set to “Self.”

The value of “Key Query” is going to depend on how you’re determining whether to follow the player. For example, if you’re using a bool then you would make it “Is Not Set”, if you’re using an enum to determine behavior you’d make it “Is Equal To” and “Key Value” would be set to the value of your enum that says it should be wandering.

Thanks for your reply kgamble.

Sadly that didn’t seem to work. I’m attaching a picture of the nodes in the behavior tree between the aggro check node and the wander sequence. The AI chooses to wander or idle if TargetToFollow is not set. It leaves the idle state immediately if TargetToFollow gets set but it does not leave the wander state if TargetToFollow gets set. Why does it work with the idle task but not the wander task?

I tried unchecking “Lock AILogic” in the wander task and this does now allow the AI to detect the player when wandering, but it also allows the AI to enter the idle state while the wander task is still running, resulting in its idle animation playing while its walking for the wander.