Skip to content

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 ​

Dictionaryplaced_entities{}
Dictionarydynamic_entities{}
Dictionaryplaced_encounters{}
Dictionaryplaced_spawners{}
Dictionaryplaced_local_events{}
Array[EncounterGroup]dynamic_encounters[]
Dictionaryplaced_interactables{}
Dictionarydynamic_interactables{}
Dictionaryplaced_dropped_items{}
Dictionarydynamic_dropped_items{}
Dictionarytaken_placements{}
Dictionarytrigger_areas{}
Dictionaryactive_controllers{}
Dictionaryentity_lod_levels{}
floatoptimization_timer0.0
intnext_controller_index0
Dictionarylod_stats{ ... }
boolbehaviors_initializedfalse
Entitycurrent_entitynull
Interactioncurrent_interactionnull
Dictionaryactive_interactions{}
WorldScenecurrent_world_scene
GameHost.SystemHubsystem_hub

Methods ​

voidprocess_lod( delta: float )
voidregister_world_objects( entities: Array, interactables: Array, trigger_areas: Array, dropped_items: Array = [], spawners: Array = [], local_events: Array = [] )
voidregister_entity( entity: Entity )
Entityget_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()
voidactivate_all_behaviors()
voidunregister_entity( entity: Entity )
voidregister_interactable( interactable: InteractableObject )
voidunregister_interactable( interactable: InteractableObject )
voidregister_trigger_area( trigger_area: TriggerArea )
voidunregister_trigger_area( trigger_area: TriggerArea )
InteractableObjectget_interactable( unique_id: int )
Array[InteractableObject]get_all_interactables()
Array[InteractableObject]get_placed_interactables()
Array[InteractableObject]get_dynamic_interactables()
TriggerAreaget_trigger_area( trigger_area_id: int )
Array[TriggerArea]get_all_trigger_areas()
voidregister_encounter( encounter: EncounterGroup, members: Array = [] )
EncounterGroupget_encounter( encounter_unique_id: int )
Array[EncounterGroup]get_all_encounters()
voidunregister_encounter( encounter: EncounterGroup )
voidregister_spawner( spawner: Spawner )
Spawnerget_spawner( spawner_unique_id: int )
Array[Spawner]get_all_spawners()
voidunregister_spawner( spawner: Spawner )
voidregister_local_event( local_event: LocalEvent )
LocalEventget_local_event( local_id: int )
Array[LocalEvent]get_all_local_events()
voidunregister_local_event( local_event: LocalEvent )
voidsettle_local_events()
voidregister_controller( entity: Entity, controller: EntityStateComponent )
voidunregister_controller( entity: Entity )
voidforce_lod_update( entity: Entity )
voidset_entity_lod_level( entity: Entity, level: GameplayConfig.LODLevel )
NPCspawn_npc( entity_id: int, position: Vector3, level: int = 0 )
Petspawn_pet( entity_id: int, summoner: Entity, position: Vector3 )
InteractableObjectspawn_interactable( interactable_id: int, position: Vector3, summoner: Entity = null )
Entityspawn_dynamic_entity( definition: EntityDefinition, position: Vector3, summoner: Entity = null )
InteractableObjectspawn_dynamic_interactable( definition: InteractableDefinition, position: Vector3, summoner: Entity = null )
DroppedItemspawn_dropped_item( instance: ItemInstance, position: Vector3, launch: bool = true, velocity: Vector3 = Vector3.ZERO )
DroppedItemspawn_dropped_currency( currency_id: int, amount: int, position: Vector3, launch: bool = true )
voidregister_dropped_item( dropped: DroppedItem, launch: bool = false, velocity: Vector3 = Vector3.ZERO, restoring: bool = false )
voidon_dropped_item_finished( dropped: DroppedItem, was_taken: bool )
Array[DroppedItem]get_all_dropped_items()
Dictionaryto_save_data()
voidfrom_save_data( save_data: Dictionary, system_hub: GameHost.SystemHub )
voidclear_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