How can I make another branch to run while another returns TaskStatus.Running ?

Tsidev

New member
Hello,
I have this Behaviour Tree for an enemy AI :

Screenshot 2023-06-24 at 19.03.59.png

At first, (Parallel Selector), the enemy wanders while checking if the player is in view. If the player attacks the enemy, or get into the enemy's view, the player will be set as the AI's target and it will proceed to the right part under the Repeater.

The AI's select a combat action (attack the player in melee with a weapon like a sword, throw a fireball etc.). Then, according to the combat action picked, it will check if the target (the player) is within range. If not, it will seek the target to make it in range to perform the action. Otherwise, it just performs the action.

When performing an action, a boolean "IsPerformingAction" is set to true, so the AI won't do anything else until the action has been performed. (The bool is set back to False at the end of the action animation or when leaving the Perform Combat Action task via its OnEnd() method).

It also triggers a global action cooldown, independent from the previous and next action, that prevents the enemy from spamming actions.
For example:
- the AI performs an action
- a cooldown is triggered (like 2s for example)
- After these 2s, the AI will be able to pick a new action and perform it. (it actually managed in the Perform Combat Action where during this cooldown, it returns TaskStatus.Running. After that cooldown has elapsed, as the AI has already performed the action, the task returns Failure and the right branch starts from the beginning).

What I want is to make the AI continuously check if the target is still within distance while it waits for the cooldown to be over.
If I set a conditional abort on the selected Selector in the screenshot to "Lower Priority", it will also abort the Perform Combat Action task when it is performing an action to seek its target. What I would like is to make the AI seek the target if it is not within distance while it waits for the cooldown to be over, not when it is performing an action (known via the boolean variable I mentioned above).

How would I do that ?

Thanks
 
The Parallel Selector will end when one of the children returns success which doesn't sound like what you want. The Parallel task will continuously run the children even if another child returns. I recommend structuring your tree similar to the Ultimate Character Controller integration tree:


This article is useful even if you are not using the Ultimate Character Controller. You'll see that at the root it has a parallel task that will check the health, and this is similar to what you want to do with checking the target.
 
The Parallel Selector will end when one of the children returns success which doesn't sound like what you want. The Parallel task will continuously run the children even if another child returns. I recommend structuring your tree similar to the Ultimate Character Controller integration tree:


This article is useful even if you are not using the Ultimate Character Controller. You'll see that at the root it has a parallel task that will check the health, and this is similar to what you want to do with checking the target.

Hello,

Thanks for your message but there is a misunderstanding. I don't have any issue with the Parallel Selector. It works totally fine. The problem lies around the Selector task, selected in the screenshot (bottom right).

Regarding the tree in the Ultimate Character Controller (which I don't have), multiple times I wanted to study it but the entire tree image is sadly unusable. The src image is 1024x246, very low quality I can't read the tasks. :cry:
 
Top