BehaviorTask ​
Inherits: Resource
Inherited by: ConsumeItemTask, CreateItemTask, DropItemTask, EquipItemTask, FollowEntityTask, IdleTask, InteractWithObjectTask, MoveToPointTask, OpenContainerTask, PatrolTask, PerformAnimationTask, SayTask, SetMetadataTask, UseAbilityAtPointTask, UseAbilityTask, UseLadderTask, UseRabbitHoleTask, WanderTask
Enhanced BehaviorTask base class with comprehensive features and robust integration. Includes centralized signal management, enhanced path failure handling, progress tracking, and LOD system support for production-ready NPC behavior.
Description ​
CORRECTED: Restored proper movement functionality and signal handling
Properties ​
bool | interruptible | true |
int | priority | 0 |
CompletionCriteria | completion_criteria | CompletionCriteria.ON_TASK_COMPLETE |
float | task_duration | 0.0 |
float | cooldown_time | 0.0 |
float | minimum_runtime | 0.0 |
PathFailureStrategy | path_failure_strategy | PathFailureStrategy.FIND_NEARBY |
int | max_recovery_attempts | 3 |
float | recovery_attempt_delay | 1.0 |
float | nearby_search_radius | 5.0 |
bool | allow_teleport_recovery | false |
Array[EntityCondition] | execution_conditions | [] |
float | max_distance_from_start | -1.0 |
bool | relative_to_spawn | false |
int | max_retry_attempts | 0 |
float | retry_delay | 1.0 |
Variables ​
String | display_name | "" |
String | description | "" |
TaskState | state | TaskState.INACTIVE |
MovementType | movement_type | MovementType.NONE |
Entity | entity | |
float | last_completion_time | -INF |
float | task_start_time | 0.0 |
Vector3 | task_start_position | Vector3.ZERO |
bool | task_actions_completed | false |
int | current_retry_attempt | 0 |
float | current_progress | 0.0 |
int | current_recovery_attempts | 0 |
Vector3 | last_failed_position | Vector3.ZERO |
Array[Vector3] | alternative_positions | [] |
Timer | duration_timer | null |
Timer | minimum_runtime_timer | null |
Timer | retry_delay_timer | null |
Timer | recovery_timer | null |
Timer | progress_update_timer | null |
bool | minimum_runtime_satisfied | false |
GameHost.SystemHub | system_hub |
Methods ​
void | apply_spawn_origin( spawn: Vector3 ) |
void | set_system_hub( p_system_hub: GameHost.SystemHub ) |
void | task_start() |
void | task_complete() |
void | task_fail( reason: String ) |
void | task_interrupt( reason: String ) |
void | notify_task_complete() |
void | update_progress( progress: float ) |
float | calculate_task_progress() |
bool | request_movement( params: Dictionary ) |
bool | is_at_destination() |
void | stop_movement() |
void | handle_path_failure() |
bool | is_active() |
bool | is_finished() |
bool | can_execute() |
void | execute_task_start() |
void | execute_task_complete() |
void | execute_task_interrupt() |
void | execute_task_fail() |
void | cleanup_timers() |
Signals ​
task_state_changed( old_state: TaskState, new_state: TaskState ) ​
Emitted when the state of the task changes (running, completed, failed ...).
task_progress_updated( progress: float ) ​
Emitted when the progress of the task changes (0 to 1).
Enumerations ​
enum TaskState ​
Task execution states
- INACTIVE =
0- Task is not running - STARTING =
1- Task is initializing - RUNNING =
2- Task is actively executing - COMPLETING =
3- Task is finishing up - COMPLETED =
4- Task finished successfully - INTERRUPTED =
5- Task was stopped before completion - FAILED =
6- Task failed due to error
enum CompletionCriteria ​
Completion criteria options
- ON_TASK_COMPLETE =
0- Complete when task actions finish - ON_DURATION_END =
1- Complete when duration timer expires - ON_EITHER =
2- Complete on whichever happens first
enum MovementType ​
Movement types for behavior tasks
- NONE =
0- No movement - MOVE_TO_POINT =
1- Move to specific location - FOLLOW_ENTITY =
2- Follow another entity - CUSTOM =
3- Custom movement handling
enum PathFailureStrategy ​
Path failure recovery strategies
- RETRY_ORIGINAL =
0- Try same position again after delay - FIND_NEARBY =
1- Find nearby accessible position - TELEPORT_CLOSE =
2- Teleport closer and try again (last resort) - SKIP_GRACEFULLY =
3- Skip with meaningful fallback behavior - WAIT_AND_RETRY =
4- Wait for obstacle to clear
Property descriptions ​
bool interruptible = true ​
Whether the task can be interrupted by external events
int priority = 0 ​
Priority of this task (higher = more important)
Timing
CompletionCriteria completion_criteria = CompletionCriteria.ON_TASK_COMPLETE ​
When to mark the task as complete
float task_duration = 0.0 ​
Duration after which the task automatically completes (0 = no limit)
float cooldown_time = 0.0 ​
Cooldown after task completion before it can run again
float minimum_runtime = 0.0 ​
Minimum time this task should run (prevents instant completion)
Movement
PathFailureStrategy path_failure_strategy = PathFailureStrategy.FIND_NEARBY ​
Strategy for handling path failures
int max_recovery_attempts = 3 ​
Maximum recovery attempts for path failures
float recovery_attempt_delay = 1.0 ​
Delay between recovery attempts
float nearby_search_radius = 5.0 ​
Search radius for nearby positions during recovery
bool allow_teleport_recovery = false ​
Whether to allow teleportation as last resort
Conditions
Array[EntityCondition] execution_conditions = [] ​
Conditions that must be met for this task to start
float max_distance_from_start = -1.0 ​
Maximum distance from start position (-1 = unlimited)
Places
bool relative_to_spawn = false ​
The places of this task (patrol points, the place to walk to, the centre of a wander, the point of an ability) are distances from where the NPC is placed, not places of the world: the same shape works wherever the NPC is put. Off = they are places of the world. The Behaviour tab of the 3D viewport sets it
Error Handling
int max_retry_attempts = 0 ​
How many times to retry if task fails
float retry_delay = 1.0 ​
Delay between retry attempts
Variable descriptions ​
String display_name = "" ​
Editor only properties
String description = "" ​
A note about what the task is for (shown in the editor).
TaskState state = TaskState.INACTIVE ​
Current task state
MovementType movement_type = MovementType.NONE ​
Type of movement this task uses
Entity entity ​
Reference to the entity executing this task
float last_completion_time = -INF ​
When the task was last completed
float task_start_time = 0.0 ​
When the task started
Vector3 task_start_position = Vector3.ZERO ​
Start position of the entity when task began
bool task_actions_completed = false ​
Whether the task's main actions have completed
int current_retry_attempt = 0 ​
Current retry attempt number
float current_progress = 0.0 ​
Current progress of the task (0.0 to 1.0)
int current_recovery_attempts = 0 ​
Current path failure recovery attempts
Vector3 last_failed_position = Vector3.ZERO ​
Last failed position for analysis
Array[Vector3] alternative_positions = [] ​
Alternative positions found during recovery
Timer duration_timer = null ​
Timer for duration-based completion
Timer minimum_runtime_timer = null ​
Timer for minimum runtime enforcement
Timer retry_delay_timer = null ​
Timer for retry delays
Timer recovery_timer = null ​
Timer for recovery attempts
Timer progress_update_timer = null ​
Timer for automatic progress updates
bool minimum_runtime_satisfied = false ​
Whether minimum runtime has been satisfied
GameHost.SystemHub system_hub ​
SystemRefs
Method descriptions ​
void apply_spawn_origin( spawn: Vector3 ) ​
Called when the schedule is set up for an NPC: a task with relative places adds the place the NPC was put at to each of them (once). Every NPC has its own copy of the script, so this changes only its own
void set_system_hub( p_system_hub: GameHost.SystemHub ) ​
Gives the task and its conditions the hub of the game systems.
void task_start() ​
Called when the task is started
void task_complete() ​
Called when the task is completed successfully
void task_fail( reason: String ) ​
Called when the task fails
void task_interrupt( reason: String ) ​
Called when the task is interrupted
void notify_task_complete() ​
Call this from your task implementation when work is done This replaces the complex _complete_task() method
void update_progress( progress: float ) ​
Update task progress (0.0 to 1.0)
float calculate_task_progress() ​
Calculate overall task progress based on completion criteria
bool request_movement( params: Dictionary ) ​
Request movement to a position (returns immediately) Request movement through the entity with proper movement type handling
bool is_at_destination() ​
Check if entity is at destination
void stop_movement() ​
Stop current movement
void handle_path_failure() ​
Handle path failure with recovery strategies
bool is_active() ​
Check if the task is currently active
bool is_finished() ​
Check if the task has completed (successfully or failed)
bool can_execute() ​
Check if task can be executed (conditions and cooldown)
void execute_task_start() ​
Override this in subclasses to implement specific task behavior
void execute_task_complete() ​
Override this in subclasses for task completion logic
void execute_task_interrupt() ​
Override this in subclasses for task interruption logic
void execute_task_fail() ​
Override this in subclasses for task failure logic
void cleanup_timers() ​
Clean up all timers and resources