Skip to content

EntityStateComponent ​

Inherits: RefCounted

Consolidated EntityStateComponent that manages all entity state systems. Uses clean signal-based communication throughout for better decoupling. Replaces EntityStatesComponent, BehaviorStateComponent, and CombatStateComponent.

Variables ​

Entityentity
boolis_initializedfalse
boolis_activefalse
ChronoManagerchrono_manager
ModularBehaviorScriptbehavior_script
ModularCombatScriptcombat_script
MovementStateComponentmovement_state_component
NavigationControllernavigation_controller
Area3Dpull_range_area
Area3Dattack_range_area
Area3Dplayer_detection_area
Array[Entity]tracked_targets[]
Timerlos_check_timer
boolplayer_detection_enabledfalse

Methods ​

voidinitialize_for_entity( system_hub: GameHost.SystemHub, entity_ref: Entity )
voidactivate( system_hub: GameHost.SystemHub )
voidcomplete_navigation_setup()
voidset_active_state( system_hub: GameHost.SystemHub, active: bool )
voidapply_lod_level( level: GameplayConfig.LODLevel )
floatget_behavior_update_interval()
boolare_detection_areas_enabled()
voidprocess_physics( delta: float )
voidpause_behavior()
voidresume_behavior()
boolactivate_schedule_by_name( schedule_name: String )
boolset_active_schedule_by_index( schedule_index: int )
TaskScheduleget_current_schedule()
voidreset_current_schedule()
voidenable_player_detection()
voiddisable_player_detection()
voidhandle_entity_death()
voidhandle_combat_entry()
voidhandle_combat_exit()
boolrequest_combat_state_change( state_name: ModularCombatScript.ActionStateName, data: Dictionary = {} )
voidactivate_player_command_state()
boolis_companion()
voidrefresh_control_state()
voidset_suspended( suspended: bool )
boolmay_start_fights()
voidset_encounter( encounter: CombatSession )
boolcommand_move_to( target_position: Vector3, walk: bool = false, min_distance: float = -1.0 )
boolcommand_move_keep_facing( target_position: Vector3, walk: bool = false, min_distance: float = -1.0 )
boolcommand_backpedal_to( target_position: Vector3, walk: bool = false, min_distance: float = -1.0 )
boolcommand_strafe_to( target_position: Vector3, strafe_direction: int, walk: bool = false, min_distance: float = -1.0 )
boolcommand_move_to_sync( target_position: Vector3, walk: bool = false, min_distance: float = -1.0 )
boolcommand_move_keep_facing_sync( target_position: Vector3, walk: bool = false, min_distance: float = -1.0 )
boolcommand_backpedal_to_sync( target_position: Vector3, walk: bool = false, min_distance: float = -1.0 )
boolcommand_strafe_to_sync( target_position: Vector3, strafe_direction: int, walk: bool = false, min_distance: float = -1.0 )
boolcommand_follow( target: Node3D, min_distance: float = 2.0, should_walk: bool = false )
voidcommand_stop()
voidset_approach_distance( distance: float )
voidhandle_player_command_input()
Dictionaryto_save_data()
voidfrom_save_data( save_data: Dictionary )
voidcleanup_timers()

Signals ​

entity_state_component_activated() ​

Entity lifecycle signals

entity_state_component_deactivated() ​

Emitted when the states of the entity are turned off.

behavior_paused() ​

Behavior system signals

behavior_resumed() ​

Emitted when the behavior of the entity runs again.

behavior_schedule_changed( old_schedule: TaskSchedule, new_schedule: TaskSchedule ) ​

Emitted when the entity switches to another schedule of tasks.

combat_state_changed( old_state: String, new_state: String ) ​

Combat system signals

player_detected() ​

Detection signals

player_lost() ​

Emitted when the entity loses sight of the player it was after.

Constants ​

  • float PLAYER_DETECTION_RADIUS = 10.0 - How near the player must come for "Player nearby" reactions (the Behaviour tab draws this circle)

Variable descriptions ​

Entity entity ​

Reference to the entity this component controls

bool is_initialized = false ​

Whether the component is fully initialized

bool is_active = false ​

Whether the component is currently active

ChronoManager chrono_manager ​

ChoronoManager for timers

ModularBehaviorScript behavior_script ​

The modular behavior script that manages all behavior logic

ModularCombatScript combat_script ​

The modular combat script that manages all combat logic

MovementStateComponent movement_state_component ​

Movement state component (kept separate as it's more complex)

NavigationController navigation_controller ​

Navigation controller (kept separate as it's more complex)

Area3D pull_range_area ​

Area3D for pull range detection

Area3D attack_range_area ​

Area3D for attack range detection

Area3D player_detection_area ​

Area3D for player detection

Array[Entity] tracked_targets = [] ​

Entities being tracked for line-of-sight checking

Timer los_check_timer ​

Timer for periodic LOS checks

bool player_detection_enabled = false ​

Whether player detection is enabled

Method descriptions ​

void initialize_for_entity( system_hub: GameHost.SystemHub, entity_ref: Entity ) ​

Initialize the component with entity reference (does NOT activate systems)

void activate( system_hub: GameHost.SystemHub ) ​

Activate all systems - called when entity becomes active

void complete_navigation_setup() ​

Complete navigation setup for entities spawned before tree entry

void set_active_state( system_hub: GameHost.SystemHub, active: bool ) ​

Set the active state of all systems

void apply_lod_level( level: GameplayConfig.LODLevel ) ​

Apply LOD level settings to behavior and detection systems This is called when the Entity's lod_level property changes

float get_behavior_update_interval() ​

Get current behavior update interval

bool are_detection_areas_enabled() ​

Check if detection areas are currently enabled

void process_physics( delta: float ) ​

Called every physics frame to update all systems

void pause_behavior() ​

Pause behavior system

void resume_behavior() ​

Resume behavior system

bool activate_schedule_by_name( schedule_name: String ) ​

Activate schedule by name

bool set_active_schedule_by_index( schedule_index: int ) ​

Set active schedule by index

TaskSchedule get_current_schedule() ​

Get current schedule

void reset_current_schedule() ​

Reset current schedule

void enable_player_detection() ​

Enable player detection

void disable_player_detection() ​

Disable player detection

void handle_entity_death() ​

Handle entity's death

void handle_combat_entry() ​

Handle the entity entering combat

void handle_combat_exit() ​

Handle the entity exiting combat

bool request_combat_state_change( state_name: ModularCombatScript.ActionStateName, data: Dictionary = {} ) ​

Request combat state change

void activate_player_command_state() ​

Activate player command state

bool is_companion() ​

Is this a party member the player does not control (an AI companion)?

void refresh_control_state() ​

Put the combat state in order after the player took over this entity or gave it up (or a stance changed): the entity in control is never moved by the combat states, a companion follows the one in control or joins the fight

void set_suspended( suspended: bool ) ​

A suspended entity (a companion in the reserve) does not detect anything and its combat script is off

bool may_start_fights() ​

May this entity start a fight on its own (a pull, an ally that is fighting)? A companion on a passive stance does not

void set_encounter( encounter: CombatSession ) ​

Set encounter for combat system

bool command_move_to( target_position: Vector3, walk: bool = false, min_distance: float = -1.0 ) ​

Command entity to move to a position

bool command_move_keep_facing( target_position: Vector3, walk: bool = false, min_distance: float = -1.0 ) ​

Command entity to move without changing facing

bool command_backpedal_to( target_position: Vector3, walk: bool = false, min_distance: float = -1.0 ) ​

Command entity to backpedal

bool command_strafe_to( target_position: Vector3, strafe_direction: int, walk: bool = false, min_distance: float = -1.0 ) ​

Command entity to strafe

bool command_move_to_sync( target_position: Vector3, walk: bool = false, min_distance: float = -1.0 ) ​

Command entity to move to a position

bool command_move_keep_facing_sync( target_position: Vector3, walk: bool = false, min_distance: float = -1.0 ) ​

Command entity to move without changing facing

bool command_backpedal_to_sync( target_position: Vector3, walk: bool = false, min_distance: float = -1.0 ) ​

Command entity to backpedal

bool command_strafe_to_sync( target_position: Vector3, strafe_direction: int, walk: bool = false, min_distance: float = -1.0 ) ​

Command entity to strafe

bool command_follow( target: Node3D, min_distance: float = 2.0, should_walk: bool = false ) ​

Command entity to follow another entity

void command_stop() ​

Command entity to stop moving

void set_approach_distance( distance: float ) ​

Set approach distance

void handle_player_command_input() ​

Handle player command input

Dictionary to_save_data() ​

Save runtime state for behavior and combat scripts

void from_save_data( save_data: Dictionary ) ​

Restore runtime state from saved data

void cleanup_timers() ​

Clean up all timers and resources