Help Understanding State Tree Task Placement for AI Combat Logic in UE5.5

Hey,

I am having a few problems with understanding where to place certain tasks in state trees.

Here is the TLDR of the main questions. I will expand upon them below.

Main Questions:

  1. How should I handle weapon firing while moving in the state tree? Is this “WeaponFire” update logic able to be on a parent node in the graph? Such as “CombatTree”?

  2. How does the “Move To Location or Actor” task node work? And, could it be causing my ai agent to walk to its previous destination when it has reached its current goal destination?

  3. Where are EQS queries best handled? Is my current setup of having a state do the EQS query and writing to a parameter in the tree, the best approach?

I am making a simple AI combat agent using State Trees. I have the initial setup down. The AI starts in a Sandboxing state where it moves around to random locations. Then, if the agent detects the player past a certain threshold, they enter the “Combat” state and go into a combat subtree linked asset.


This is the main State Tree.

In the combat tree I want the AI to just calculate where it’s best position to be at is and then fire at the player when they are able to. To get rid of complications right now I am only assuming the AI can fire their gun every two seconds. We will not be performing checks on any weapons systems at the moment.


This is the Combat State Tree

The first problem: When the AI enters the combat tree and leaves the Sandboxing state it will INITIALLY try calculating the best spot to get to and then go there BUT once it reaches that target combat spot it will attempt to go back to the last location it was traveling to in the Sandboxing state. If it has time to reach that location (before the delay in the combat Chase state finishes) and it successfully gets there it will no longer try to reach that location. What could be causing this to happen? Is it a problem with the Move To Location or Actor node?


Here, the yellow debug sphere is the TargetLocation for the combat tree and the blue spheres were the random locations the AI was naving towards in its sandboxing state. Once at the combat TargetLocation, the AI will then turn towards the last random location (the blue sphere on the left) and attempt to walk towards it even though we are still in the Combat State Tree.


Here is the debug of the initial change to the combat state tree on an event being fired on the AI controller.

The second problem is really about where weapon firing or attacking logic should go. The ai should be firing its weapon if it can, even if it currently moving to a location, hiding behind cover, or standing in place, as long as it is in the Combat State Tree. I tried having this in the “CombatTree” state in the CombatTree linked asset but I ran into some issues when having it there. Should weapon firing logic be a global task in the Combat State Tree that never fires FinishTask but just constantly checks whether it can and should fire its gun?

Third, where do most people perform their EQS queries? I am currently using a task to perform a few EQS queries and then updating a “TargetLocation” parameter on the State Tree. Is there a better method for doing this?

Please let me know of any insights you have to these problems. I have worked through the tutorials on the UE website and watched other videos on State Trees, but I am still having trouble understanding when a state is “finished” and how tasks on states and child states are executed.