The Can See Target branch contains the attack logic used when a target is visible. It is divided into multiple branches and two subtrees. With those subtrees collapsed to references, the branch looks like:

A Lower Priority conditional abort is used so the Is Target In Sight task will be reevaluated if any branch to the right of the Can See Target branch is active. When Is Target In Sight returns Success it means that there is a target within the agent’s field of view. The Start Stop Ability task then requests that Speed Change start. This is not a stop-running command; the configured Speed Change settings determine the resulting movement. A Selector is placed so the left branch can attack and the right branch will be run after the attacking is finished. Let’s look at the left branch first. The Parallel task is used to run both the left and right branches at the same time. This allows the agent to possibly change targets while still attacking the original target. The left branch looks like the following:

  At the top of this branch is a Repeater. The Repeater will allow the child tasks to be reevaluated each tick. The child Sequence task then contains two children: Is Target In Sight and Return Success. The Is Target In Sight is the same as the one at the top of the Can See Target branch except this one will store the target in the Possible Target variable instead of the Target variable. This allows the existing target to be kept if for some reason the agent doesn’t want to switch to the new target that just came within sight. The branch below the Return Success looks similar to a setup before where we first compare the Possible Target variable to the current Target variable and if it’s different then there’s a chance that the agent should switch based on the Random Probability. If the agent should switch then the current target is added to the Ignore Targets set and the Set Shared GameObject task will set the Possible Target to the Target. As the agent is continuously checking for new targets they are also attacking with the branch on the right:

Without the Attack subtree pulled in this is a small branch which first determines the best weapon for the current game state. This task is only run once and allows the agent to have a weapon ready to go when the Attack branch runs. The Start Equip Unequip task will equip the Item Set returned by the Determine Weapon task. The rightmost task is a Behavior Tree Reference task which loads the Attack branch. The Attack branch is explained on this page but a quick summary is that it will allow the agent to actually fire at the target. As soon as the agent is done attacking (because the target died or is no longer in sight), the following branch will run:

The first Reset clears its configured combat references and flags while deliberately retaining Target for Is Alive. If the target is alive but no longer visible, the branch records its last position and sets Search to true. A later Reset clears Target. Reset only changes its explicitly bound fields, sets Can Attack true, and may cancel backup or stop Aim according to its options. It does not restore unrelated variables such as Waypoints, Field Of View, Max Distance, Target Position, or custom variables.