ModularBehaviorScript ​
Inherits: DatabaseResource < Resource
ModularBehaviorScript coordinates behavior schedules and reactions for entities. Clean signal-based version that doesn't require references to state components. Communicates purely through signals for better decoupling.
Properties ​
bool | enabled | true |
Array[TaskSchedule] | schedules | [] |
Array[BehaviorReaction] | schedule_reactions | [] |
FallbackBehaviorType | fallback_behavior | FallbackBehaviorType.WANDER |
float | wander_radius | 5.0 |
bool | return_to_spawn | true |
Variables ​
Entity | entity | |
TaskSchedule | current_schedule | null |
TaskSchedule | fallback_schedule | null |
TaskSchedule | previous_schedule | null |
float | last_evaluation_time | 0.0 |
float | evaluation_interval | 2.0 |
Methods ​
void | setup( system_hub: GameHost.SystemHub, entity_ref: Entity ) |
bool | is_held_by_reaction() |
void | reevaluate_now() |
bool | set_active_schedule( new_schedule: TaskSchedule ) |
bool | set_active_schedule_by_index( index: int ) |
bool | activate_schedule_by_name( schedule_name: String ) |
TaskSchedule | get_current_schedule() |
void | reset_current_schedule() |
BehaviorTask | get_current_task() |
void | pause_behavior() |
void | resume_behavior() |
bool | is_behavior_active() |
void | process_behavior( delta: float ) |
void | on_player_detection_changed( player_nearby: bool ) |
void | handle_formation_update() |
void | handle_entity_death() |
int | get_id() |
void | set_id( new_id: int ) |
Dictionary | to_save_data() |
void | from_save_data( save_data: Dictionary ) |
void | cleanup() |
Signals ​
schedule_changed( old_schedule: TaskSchedule, new_schedule: TaskSchedule ) ​
Emitted when the active schedule changes
behavior_paused() ​
Emitted when behavior is paused
behavior_resumed() ​
Emitted when behavior is resumed
schedule_activation_failed( schedule_name: String, reason: String ) ​
Emitted when a schedule activation fails
Enumerations ​
enum FallbackBehaviorType ​
The options of fallback behavior type: wander, move to spawn, idle at current, follow nearest ally.
- WANDER =
0- Auto-create WanderSchedule with specified radius - MOVE_TO_SPAWN =
1- Single task: move to spawn point then idle - IDLE_AT_CURRENT =
2- Single task: idle with animations - FOLLOW_NEAREST_ALLY =
3- For pets without orders
Property descriptions ​
Script Settings
bool enabled = true ​
Whether this script is currently enabled
Array[TaskSchedule] schedules = [] ​
Available schedules in priority order (index 0 = highest priority)
Array[BehaviorReaction] schedule_reactions = [] ​
Event-driven reactions that can switch schedules
Fallback Behavior
FallbackBehaviorType fallback_behavior = FallbackBehaviorType.WANDER ​
What to do when no schedule is valid or available
float wander_radius = 5.0 ​
Radius for wander fallback behavior
bool return_to_spawn = true ​
Whether to return to spawn point for fallback
Variable descriptions ​
Entity entity ​
Reference to the entity using this script
TaskSchedule current_schedule = null ​
Currently active schedule
TaskSchedule fallback_schedule = null ​
Fallback schedule created automatically
TaskSchedule previous_schedule = null ​
Previous schedule (for reaction returns)
float last_evaluation_time = 0.0 ​
Last time we evaluated schedule conditions
float evaluation_interval = 2.0 ​
Evaluation interval to prevent excessive checking
Method descriptions ​
void setup( system_hub: GameHost.SystemHub, entity_ref: Entity ) ​
Initialize the behavior script with entity reference only
bool is_held_by_reaction() ​
Is a reaction that switched the schedule still in charge (it is until it returns, or for good when it does not return)
void reevaluate_now() ​
Picks the schedule that fits now, without waiting for the next periodic check
bool set_active_schedule( new_schedule: TaskSchedule ) ​
Set the active schedule with signal emission
bool set_active_schedule_by_index( index: int ) ​
Set active schedule by index
bool activate_schedule_by_name( schedule_name: String ) ​
Find and activate schedule by name
TaskSchedule get_current_schedule() ​
Get the currently active schedule
void reset_current_schedule() ​
Reset current schedule to beginning
BehaviorTask get_current_task() ​
Get the current task being executed
void pause_behavior() ​
Pause behavior processing
void resume_behavior() ​
Resume behavior processing
bool is_behavior_active() ​
Check if behavior is currently active
void process_behavior( delta: float ) ​
Called every frame to process behavior logic
void on_player_detection_changed( player_nearby: bool ) ​
Handle player detection changes (called via signal)
void handle_formation_update() ​
Handle formation updates (called via signal)
void handle_entity_death() ​
Handle entity death (called via signal)
int get_id() ​
Get the ID of this behavior script
void set_id( new_id: int ) ​
Set the ID of this behavior script
Dictionary to_save_data() ​
Save runtime state for persistence
void from_save_data( save_data: Dictionary ) ​
Restore runtime state from saved data
void cleanup() ​
Cleanup all resources when script is no longer needed