Skip to content

PatrolTask ​

Inherits: BehaviorTask < Resource

Modern PatrolTask for entities that follow patrol routes. Supports multiple waypoints, different patrol patterns, and dynamic adjustments.

Description ​

FIXES APPLIED:

  • Removed async/await movement calls
  • Fixed navigation signal timing (setup BEFORE movement)
  • Eliminated duplicate state tracking (single source of truth)
  • Centralized signal management with automatic cleanup
  • Unique timer naming to prevent conflicts
  • Proper resource cleanup in all exit paths

Properties ​

Array[Vector3]waypoints[]
PatrolPatternpatrol_patternPatrolPattern.LOOP
boolforce_walkingtrue
floatwait_time_at_waypoint2.0

Variables ​

intcurrent_waypoint_index0
boolmoving_forwardtrue
Timerwaypoint_wait_timernull
boolwaiting_at_waypointfalse

Methods ​

voidexecute_task_start()
voidexecute_task_complete()
voidexecute_task_interrupt()
voidexecute_task_fail()
voidhandle_path_failure()
Vector3get_current_waypoint()
Vector3get_next_waypoint()
voidadd_waypoint( position: Vector3 )
voidinsert_waypoint( index: int, position: Vector3 )
voidremove_waypoint( index: int )
voidclear_waypoints()

Enumerations ​

enum PatrolPattern ​

The options of patrol pattern: loop, ping pong, random, once.

  • LOOP = 0 - Start -> End -> Start -> End...
  • PING_PONG = 1 - Start -> End -> End-1 -> ... -> Start -> ...
  • RANDOM = 2 - Random waypoint selection
  • ONCE = 3 - Start -> End, then complete

Property descriptions ​

Patrol Route

Array[Vector3] waypoints = [] ​

List of world positions to patrol between

PatrolPattern patrol_pattern = PatrolPattern.LOOP ​

How to move through the waypoints

bool force_walking = true ​

Whether to always walk instead of run

float wait_time_at_waypoint = 2.0 ​

Time to wait at each waypoint before moving to next

Variable descriptions ​

int current_waypoint_index = 0 ​

Current index in the waypoints array

bool moving_forward = true ​

Whether moving forward through waypoints (used for PING_PONG pattern)

Timer waypoint_wait_timer = null ​

Timer for waiting at waypoints

bool waiting_at_waypoint = false ​

Whether we're currently waiting at a waypoint

Method descriptions ​

void execute_task_start() ​

Starts the task.

void execute_task_complete() ​

Called when the task finishes well.

void execute_task_interrupt() ​

Called when something interrupts the task.

void execute_task_fail() ​

Called when the task fails.

void handle_path_failure() ​

When a waypoint cannot be reached, the entity goes to the next one.

Vector3 get_current_waypoint() ​

The waypoint the entity goes to now.

Vector3 get_next_waypoint() ​

The waypoint after it.

void add_waypoint( position: Vector3 ) ​

Adds a waypoint at the end of the route.

void insert_waypoint( index: int, position: Vector3 ) ​

Inserts a waypoint at a place of the route.

void remove_waypoint( index: int ) ​

Removes a waypoint from the route.

void clear_waypoints() ​

Removes every waypoint.