ObjectRegistry ​
Inherits: RefCounted
ObjectRegistry - manages all NPCs, Interactables, Trigger areas, and special Encounters with advanced LOD system Integrated with CombatSystem's encounter management for coordinated combat behavior Features configurable LOD system via GameplayConfig, behavior optimization, and comprehensive performance management Handles registration, spawning, interaction tracking, and state management Provides centralized access for quest systems, events, and ability effects
Variables ​
Dictionary | placed_entities | {} |
Dictionary | dynamic_entities | {} |
Dictionary | placed_encounters | {} |
Dictionary | placed_spawners | {} |
Dictionary | placed_local_events | {} |
Array[EncounterGroup] | dynamic_encounters | [] |
Dictionary | placed_interactables | {} |
Dictionary | dynamic_interactables | {} |
Dictionary | placed_dropped_items | {} |
Dictionary | dynamic_dropped_items | {} |
Dictionary | taken_placements | {} |
Dictionary | trigger_areas | {} |
Dictionary | active_controllers | {} |
Dictionary | entity_lod_levels | {} |
float | optimization_timer | 0.0 |
int | next_controller_index | 0 |
Dictionary | lod_stats | { ... } |
bool | behaviors_initialized | false |
Entity | current_entity | null |
Interaction | current_interaction | null |
Dictionary | active_interactions | {} |
WorldScene | current_world_scene | |
GameHost.SystemHub | system_hub |
Methods ​
void | process_lod( delta: float ) |
void | register_world_objects( entities: Array, interactables: Array, trigger_areas: Array, dropped_items: Array = [], spawners: Array = [], local_events: Array = [] ) |
void | register_entity( entity: Entity ) |
Entity | get_entity( entity_unique_id: int ) |
Array[Entity] | get_entities_by_data_id( definition_id: int ) |
Array[Entity] | get_all_entities() |
Array[Entity] | get_placed_entities() |
Array[Entity] | get_dynamic_entities() |
void | activate_all_behaviors() |
void | unregister_entity( entity: Entity ) |
void | register_interactable( interactable: InteractableObject ) |
void | unregister_interactable( interactable: InteractableObject ) |
void | register_trigger_area( trigger_area: TriggerArea ) |
void | unregister_trigger_area( trigger_area: TriggerArea ) |
InteractableObject | get_interactable( unique_id: int ) |
Array[InteractableObject] | get_all_interactables() |
Array[InteractableObject] | get_placed_interactables() |
Array[InteractableObject] | get_dynamic_interactables() |
TriggerArea | get_trigger_area( trigger_area_id: int ) |
Array[TriggerArea] | get_all_trigger_areas() |
void | register_encounter( encounter: EncounterGroup, members: Array = [] ) |
EncounterGroup | get_encounter( encounter_unique_id: int ) |
Array[EncounterGroup] | get_all_encounters() |
void | unregister_encounter( encounter: EncounterGroup ) |
void | register_spawner( spawner: Spawner ) |
Spawner | get_spawner( spawner_unique_id: int ) |
Array[Spawner] | get_all_spawners() |
void | unregister_spawner( spawner: Spawner ) |
void | register_local_event( local_event: LocalEvent ) |
LocalEvent | get_local_event( local_id: int ) |
Array[LocalEvent] | get_all_local_events() |
void | unregister_local_event( local_event: LocalEvent ) |
void | settle_local_events() |
void | register_controller( entity: Entity, controller: EntityStateComponent ) |
void | unregister_controller( entity: Entity ) |
void | force_lod_update( entity: Entity ) |
void | set_entity_lod_level( entity: Entity, level: GameplayConfig.LODLevel ) |
NPC | spawn_npc( entity_id: int, position: Vector3, level: int = 0 ) |
Pet | spawn_pet( entity_id: int, summoner: Entity, position: Vector3 ) |
InteractableObject | spawn_interactable( interactable_id: int, position: Vector3, summoner: Entity = null ) |
Entity | spawn_dynamic_entity( definition: EntityDefinition, position: Vector3, summoner: Entity = null ) |
InteractableObject | spawn_dynamic_interactable( definition: InteractableDefinition, position: Vector3, summoner: Entity = null ) |
DroppedItem | spawn_dropped_item( instance: ItemInstance, position: Vector3, launch: bool = true, velocity: Vector3 = Vector3.ZERO ) |
DroppedItem | spawn_dropped_currency( currency_id: int, amount: int, position: Vector3, launch: bool = true ) |
void | register_dropped_item( dropped: DroppedItem, launch: bool = false, velocity: Vector3 = Vector3.ZERO, restoring: bool = false ) |
void | on_dropped_item_finished( dropped: DroppedItem, was_taken: bool ) |
Array[DroppedItem] | get_all_dropped_items() |
Dictionary | to_save_data() |
void | from_save_data( save_data: Dictionary, system_hub: GameHost.SystemHub ) |
void | clear_all() |
Signals ​
entity_registered( entity: Entity ) ​
========== SIGNALS ==========
entity_unregistered( entity: Entity ) ​
Emitted when an entity is removed from the registry.
interactable_registered( interactable: InteractableObject ) ​
Emitted when an object is added to the registry.
interactable_unregistered( interactable: InteractableObject ) ​
Emitted when an object is removed from the registry.
dropped_item_registered( dropped: DroppedItem ) ​
Emitted when a dropped item is put in the world.
dropped_item_unregistered( dropped: DroppedItem, was_taken: bool ) ​
Emitted when a dropped item leaves the world: taken (a character took it) or not (it expired or was removed).
Variable descriptions ​
Dictionary placed_entities = ​
Dictionary of placed NPCs/entities keyed by unique_id for fast lookups
Dictionary dynamic_entities = ​
Dictionary of dynamic NPCs/entities keyed by instance_id (no UniqueEntityData)
Dictionary placed_encounters = ​
Dictionary of encounters keyed by unique_id for fast lookups
Dictionary placed_spawners = ​
The spawners of the world by the id of their record
Dictionary placed_local_events = ​
The local events of the world (small rules of the place, nodes of its scene) by their local id
Array[EncounterGroup] dynamic_encounters = [] ​
Array of dynamic encounters (no unique ID)
Dictionary placed_interactables = ​
Dictionary of placed interactables keyed by unique_id for fast lookups
Dictionary dynamic_interactables = ​
Dictionary of dynamic interactables keyed by instance_id (no UniqueInteractableData)
Dictionary placed_dropped_items = ​
Dropped items placed by hand in the world scene, by their placement id
Dictionary dynamic_dropped_items = ​
Dropped items made while the game runs (dropped by the player, loot, events), by instance id
Dictionary taken_placements = ​
The placed dropped items that were taken, by placement id: the seconds until they lie there again (-1 = never)
Dictionary trigger_areas = ​
Dictionary of placed trigger areas keyed by unique_id for fast lookups
Dictionary active_controllers = ​
Dictionary of all active behavior controllers keyed by entity instance ID
Dictionary entity_lod_levels = ​
Track current LOD level for each entity (keyed by instance ID)
float optimization_timer = 0.0 ​
Enhanced optimization variables
int next_controller_index = 0 ​
The next place in the round robin that decides which entities think this frame.
Dictionary lod_stats ​
Performance monitoring - tracks count per LOD level
bool behaviors_initialized = false ​
========== INITIALIZATION STATE ==========
Entity current_entity = null ​
========== INTERACTION MANAGEMENT ==========
Interaction current_interaction = null ​
The interaction that is running now.
Dictionary active_interactions = ​
Track active interactions across all NPCs
WorldScene current_world_scene ​
========== ACTIVE WORLD SCENE ==========
GameHost.SystemHub system_hub ​
========== Required Systems ==========
Method descriptions ​
void process_lod( delta: float ) ​
Thins out the behaviour of what is far from the player (called every frame by the WorldContainer: a RefCounted has no process of its own)
void register_world_objects( entities: Array, interactables: Array, trigger_areas: Array, dropped_items: Array = [], spawners: Array = [], local_events: Array = [] ) ​
Register all world objects at once (called by WorldContainer after world loads) This handles pre-placed objects from the WorldScene containers
void register_entity( entity: Entity ) ​
Register an entity with the manager (called during world loading)
Entity get_entity( entity_unique_id: int ) ​
Get entity by unique_id (for event system calls, conditions, etc.)
Array[Entity] get_entities_by_data_id( definition_id: int ) ​
Every entity of one definition (the NPCs of one kind), placed or spawned
Array[Entity] get_all_entities() ​
Get all registered entities (placed + dynamic)
Array[Entity] get_placed_entities() ​
Get only placed entities
Array[Entity] get_dynamic_entities() ​
Get only dynamic entities
void activate_all_behaviors() ​
Activate behaviors for all registered NPCs (called after all NPCs are initialized)
void unregister_entity( entity: Entity ) ​
Unregister an entity from the manager
void register_interactable( interactable: InteractableObject ) ​
Register an interactable with the manager (called during world loading or spawning)
void unregister_interactable( interactable: InteractableObject ) ​
Unregister an interactable from the manager
void register_trigger_area( trigger_area: TriggerArea ) ​
Register an trigger area with the manager (called during world loading or spawning)
void unregister_trigger_area( trigger_area: TriggerArea ) ​
Unregister an trigger area from the manager
InteractableObject get_interactable( unique_id: int ) ​
Find interactable object by unique ID (delegates to WorldScene)
Array[InteractableObject] get_all_interactables() ​
Get all interactable objects (placed + dynamic)
Array[InteractableObject] get_placed_interactables() ​
Get only placed interactables
Array[InteractableObject] get_dynamic_interactables() ​
Get only dynamic interactables
TriggerArea get_trigger_area( trigger_area_id: int ) ​
Get all trigger areas
Array[TriggerArea] get_all_trigger_areas() ​
Get all trigger areas
void register_encounter( encounter: EncounterGroup, members: Array = [] ) ​
Register an encounter group with the manager (initializes it with its members and connects their signals). The group is a child of the world container while the world is loaded.
EncounterGroup get_encounter( encounter_unique_id: int ) ​
Get encounter by unique_id
Array[EncounterGroup] get_all_encounters() ​
Get all registered encounters (placed + dynamic)
void unregister_encounter( encounter: EncounterGroup ) ​
Unregister a Encounter from the manager
void register_spawner( spawner: Spawner ) ​
Register a spawner: it starts working (it makes things while a player is near).
Spawner get_spawner( spawner_unique_id: int ) ​
The spawner of a record id (null when there is none).
Array[Spawner] get_all_spawners() ​
Every spawner of the world.
void unregister_spawner( spawner: Spawner ) ​
Takes a spawner out of the registry (it stops working).
void register_local_event( local_event: LocalEvent ) ​
Register a local event: it makes its runtime copy. It does not listen yet (see settle_local_events)
LocalEvent get_local_event( local_id: int ) ​
The local event with a number (null when there is none)
Array[LocalEvent] get_all_local_events() ​
Every local event of the world
void unregister_local_event( local_event: LocalEvent ) ​
Takes a local event out of the registry (it stops listening)
void settle_local_events() ​
The world has put back what it remembers: the local events start to listen (so a switch put back in the position it was saved in does not set a rule off)
void register_controller( entity: Entity, controller: EntityStateComponent ) ​
Register a behavior controller
void unregister_controller( entity: Entity ) ​
Unregister a behavior controller
void force_lod_update( entity: Entity ) ​
Force LOD update for a specific entity (useful when entity becomes important)
void set_entity_lod_level( entity: Entity, level: GameplayConfig.LODLevel ) ​
Set LOD level directly for an entity (bypasses distance calculation)
NPC spawn_npc( entity_id: int, position: Vector3, level: int = 0 ) ​
Spawn NPC at specified position (with UniqueEntityData)
Pet spawn_pet( entity_id: int, summoner: Entity, position: Vector3 ) ​
Spawn Pet (temporary, no UniqueEntityData)
InteractableObject spawn_interactable( interactable_id: int, position: Vector3, summoner: Entity = null ) ​
Spawn interactable at specified position
Entity spawn_dynamic_entity( definition: EntityDefinition, position: Vector3, summoner: Entity = null ) ​
Spawn dynamic entity (for save/load restoration of dynamic NPCs) This spawns an entity without UniqueEntityData (dynamic entity)
InteractableObject spawn_dynamic_interactable( definition: InteractableDefinition, position: Vector3, summoner: Entity = null ) ​
Spawn dynamic interactable (for save/load restoration of dynamic interactables) This spawns an interactable without UniqueInteractableData (dynamic interactable)
DroppedItem spawn_dropped_item( instance: ItemInstance, position: Vector3, launch: bool = true, velocity: Vector3 = Vector3.ZERO ) ​
Makes an item lie in the world: a dropped item of the item instance at a position, thrown (launch) or put there. Gives it, or null when dropped items are off in the Gameplay Config or the world cannot hold it
DroppedItem spawn_dropped_currency( currency_id: int, amount: int, position: Vector3, launch: bool = true ) ​
Makes a pile of a currency lie in the world, like spawn_dropped_item
void register_dropped_item( dropped: DroppedItem, launch: bool = false, velocity: Vector3 = Vector3.ZERO, restoring: bool = false ) ​
Puts a dropped item in the registry: one placed by hand (it has a placement id) or one made while playing. A placed item that was taken stays taken
void on_dropped_item_finished( dropped: DroppedItem, was_taken: bool ) ​
Called by a dropped item when it is gone: a placed one is remembered as taken (and comes back after its respawn time), a made one is forgotten
Array[DroppedItem] get_all_dropped_items() ​
Every dropped item that lies in the world now
Dictionary to_save_data() ​
Save instance runtime state Save NPCS, INTERACTABLES & ENCOUNTERS IMPORTANT: Dynamic entities of class Pet are NOT saved (they respawn from effects)
void from_save_data( save_data: Dictionary, system_hub: GameHost.SystemHub ) ​
Load instance runtime state - COMPREHENSIVE VERSION Handles:
- Restoring placed entities (with removal of entities not in save)
- Spawning dynamic entities from save data
- Restoring placed interactables (with removal)
- Spawning dynamic interactables from save data
- Restoring encounters
void clear_all() ​
Clear all tracked entities, encounters, and containers