Boss AI Behavior Tree - Combining Melee Attack with Continuous Bee Spawning

Hi everyone,

I’m working on a boss AI using behavior trees and could use some help.

Current Setup:

  • Special Attack: The boss wanders around and continuously spawns bees.
    • Behavior Tree Logic:
      • A Sequence Node contains a Simple Parallel Node.
      • Simple Parallel Node:
        • Main Task: “Move and Wait” task (wandering), which is a single task and works fine.
        • Background Task: A loop that spawns a bee and waits 1 second, repeated 5 times.
  • Player Proximity Check:
    • A Decorator checks if the player is within a minimum radius.
    • If the player is close, a sequence with multiple tasks (melee attack) should start.

What I Need:

  • The boss should keep spawning bees continuously, even when performing the melee attack.
  • When the player gets close, the boss should stop wandering and start the melee attack sequence.
  • Bee spawning should not stop when switching from wandering to melee attacking.

Issues I’m Facing:

  • When the melee attack sequence starts, the bee spawning stops because it’s tied to the wandering sequence.
  • I tried using a subtree for the main task, but it didn’t work.
  • The wandering works because it’s a single task, but the melee sequence has multiple tasks, and integrating it is challenging.

Question:

  • How can I restructure my behavior tree so that the boss continues to spawn bees continuously, regardless of whether he’s wandering or attacking?

Any suggestions or examples would be greatly appreciated!

Wandering and spawn

Melee sequence

Current behaviour

Thanks in advance!

bump

No one? I also attempted to swap the background task logic with the main task logic and create a task for the loop instead. However, it seems that the loop inside the task executes the completed and just one loop once for some reason.

BTTask_BeeQueen_Loop_Attack:

It is expected that the task executes only once because there isn’t actually anything that triggers it continuously. Instead of plugging your code after the Event Receive Execute AI node, you can call a custom event after that, and make that event execute the rest of your code. Keep the conditions to call that event in the Event Receive Execute AI node and if they are met, call that again. Or you can just call that again once it’s done with no extra conditions if you want (while making sure you’re not calling it while it’s still running) but plug in a Finish Execute node at the end of the execution chain that the custom event triggers. That would trigger your task continuously if the other side of your parallel node doesn’t get triggered.

I’m not sure if I understood you correctly, but I managed to make it work. Thanks! :grin:

BTTask_QueenBee_Loop_Attack:

Behaviour tree:

BTTask_MoveAndWait:

I made the following changes:

  1. In the BTTask_QueenBee_Loop_Attack (as you suggested), I added a Set Timer By Event node to execute the custom event as many times as needed.
  2. In the Behavior Tree, as background tasks, I added a Selector, one for the melee attack and the other for wandering.
  3. Since every time the queen bee used the melee attack and the flow moved back to the wandering task, the service BTService_RandomLocation was triggered, causing a new position to be returned before the last one was completed (changing the position every time a melee attack was executed), so I added the BTTask_MoveAndWait task inside the reset sequence.
  4. Lastly, because the reset sequence is a child of the melee phase, when the player was moving within range, the melee was no longer triggered until the wandering task was finished. To fix this, I added the same decorator from the parent, set “Inverse Condition,” and set Observer Aborts to Self.

After that this is the result :slight_smile:

Thank you again for the suggestion!

I hope this will help someone in the future.