Patrol, Chase, and Attack
Use this graph when an agent should patrol until it detects a target, pursue that target, and attack only at close range.
In the editor
- Create a GameObject Shared Variable named Target, then assign the target at runtime or from the Inspector.
- Connect Start to Patrol, and add Patrol, Chase, and Attack Action States from left to right.
- Connect Patrol to Chase. Replace the default State Finished with Is In Line Of Sight, select Target as the other GameObject, and use Continuous evaluation.
- Connect Chase to Attack. Replace State Finished with Within Distance, select Target, and set the attack distance.
- Connect Chase back to Patrol. Replace State Finished with another Is In Line Of Sight Condition configured to require blocked line of sight.
- Connect Attack back to Chase with State Finished so the pursuit decision is evaluated again after the attack Action completes.

The Patrol and Chase states should contain Actions that remain Running while they perform their mode. Attack can contain a finite animation, damage, or project-specific combat sequence.
How it runs
Patrol remains active until the target is visible. Chase then runs while the target stays visible and outside attack range. Entering range activates Attack; when the attack finishes, the graph returns to Chase and reevaluates range and visibility.
If the target moves out of sight during Chase, the blocked-line-of-sight transition returns the agent to Patrol. If the game should search the last known position first, insert a Search state between Chase and Patrol and store that position in a Shared Variable.
Key choices
- Set the Chase-to-Attack and Chase-to-Patrol transitions to Continuous so movement can change the active mode immediately.
- Use All Condition Mode when Attack also requires a valid target, ammunition, or another rule.
- Keep sensing in Conditions and movement or combat in Actions. This makes each transition explain why the mode changed.
- Add the Attack with Cooldown pattern when returning from Attack should not permit an immediate second attack.
Verify in Play Mode
Move the target through the detection and attack boundaries. Confirm that the active highlight advances Patrol to Chase to Attack, returns to Chase after the attack finishes, and returns to Patrol when sight is lost.