Moving and shooting AI - but also standing and shooting AI

I am trying to use behavior trees to have my AI turn to aim at a target, and shoot at it, while at the same time moving towards a different location.

This I can do with a Simple Parallel node, that has the MoveTo task as its primary task and the shooting (and reloading, etc.) as the secondary (the graph that is run while MoveTo is running).
This part works fine, when the pawn moves, the shooting and reload and so on happen. Here is the problem:

I must now, as I can understand, create a duplicate of the graph for when MoveTo is NOT running; i.e. so that the AI will not stop shooting, reloading, etc. when not moving to a different location.
In this simple case, I already have doubled my node count. And Imagine if I want to turn while moving and shooting? Now I have to duplicate to another Simple Parallel.
Some of the problem is that the primary task can only by a single task and not a branch.

Some workarounds I have considered:

  • Sub-tress using Run Behavior: Doesn’t seem to work with Simple Parallel. The subtree is never run when it is the primary task of a Simple Parallel.

  • Moving the movement behavior to the AIController blueprint: This means that I am splitting some code into behavior trees and some in the AIController blueprint, more places for parallel things to happen, more complex perhaps.

  • Running two behavior trees: Seems to go against the various single Blackboard variables. From the engine code it seems that only one behavior per controller is expected, though I think multiple BehaviorTree Components can be used. Harder to maintain.

  • Writing a new MoveTo task that does not finish execution but keeps running, making the Simple Parallel never stop.

  • Writing a new MoveTo task that makes the pawn move over time but has the node finish instantly, so that it doesn’t block the branch.

It seems like many of the examples and tutorials I run into expects movement and attacking to be two separate, non-overlapping actions.

Thank you for reading this far :slight_smile:

All I did was change finish mode to delayed on the simple parallel node and it seems to work.

1 Like