Goal

Use this pattern when Patrol is the fallback behavior and Chase should take over whenever the agent can see an enemy.

Tree structure

Put a Sequence containing Can See Enemy? and Chase Enemy first under a Selector. Put Patrol second. Select the Sequence and set Abort Type to Both.

A Selector prioritizes a Chase Sequence with a Both conditional abort over the fallback Patrol action.

How it runs

The Selector tries the chase Sequence before Patrol. While Patrol runs, the Lower Priority abort reevaluates Can See Enemy and interrupts Patrol when an enemy becomes visible. While Chase runs, the Self abort reevaluates the same Conditional and returns control to Patrol when sight is lost.

Keep perception inside the Conditional and movement inside the Actions. Store the visible target in a Shared Variable so Chase reads the same object that the condition found.

Variations

Add a Search branch between Chase and Patrol when the agent should investigate the last known position. Use separate visibility and target-validity conditions when losing sight should not immediately discard the target.

Tasks used in this tree

Selector, Sequence, Conditionals, and Conditional Aborts.