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 | [] |
PatrolPattern | patrol_pattern | PatrolPattern.LOOP |
bool | force_walking | true |
float | wait_time_at_waypoint | 2.0 |
Variables ​
int | current_waypoint_index | 0 |
bool | moving_forward | true |
Timer | waypoint_wait_timer | null |
bool | waiting_at_waypoint | false |
Methods ​
void | execute_task_start() |
void | execute_task_complete() |
void | execute_task_interrupt() |
void | execute_task_fail() |
void | handle_path_failure() |
Vector3 | get_current_waypoint() |
Vector3 | get_next_waypoint() |
void | add_waypoint( position: Vector3 ) |
void | insert_waypoint( index: int, position: Vector3 ) |
void | remove_waypoint( index: int ) |
void | clear_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.