Entities: how they are built ​
The Entities chapter explains the editors. This page explains the code: how a node becomes an entity, what it is made of, and what happens when it fights, dies, is summoned or is used.
Definitions ​
| Class | Editor | Notes |
|---|---|---|
EntityDefinition | (base) | The model scene and scale, the collision shape, the animation type and packages, the voice and footstep audio, entity_tags |
NPCDefinition | NPCs | default_level, experience_worth, faction, stats_data, loot_table with loot_table_logic, inventory, the abilities and AI scripts, the animation tags |
CharacterDefinition | Playable Character | A player_class, starting_level, equipment_override, inventory |
CustomCharacterDefinition | (character creation) | A character made in the creation window: the profile, body type, voice, facial meshes, colors and blend shapes |
PlayerClassDefinition | Player Classes | stats_data, starter_equipment, level_rewards, locked_equipment_slots, skill_trees, the abilities, the AI scripts. Not an EntityDefinition: a character has a class |
InteractableDefinition | Interactables | The scene, targeting flags, stats_data, the lock, the cooldown, one interaction |
A definition is a DatabaseResource and is never changed while the game runs. A placed NPC carries a UniqueEntityData with overrides (level, scale, faction, experience, scripts, loot, inventory, stats, spawn delay, respawn timer, an interaction); UniqueInteractableData does the same for objects.
From a node to an entity ​
- A scene node (
Player,NPC,Pet,InteractableObject) is made and itsdefinition(andunique_data) is set. initialize_entity(system_hub)builds everything.EntityComponentRegistry.setupcreates the rig, collision, audio, stats, effects, pets, inventory, equipment, abilities, the nameplate marker, the state component and the map marker;create_mediatorthen wires the components together.- Placed NPCs are initialized by
ObjectRegistry.register_entity; players by the party manager.ObjectRegistry.spawn_npc,spawn_petandspawn_interactableregister what they spawn, so events, encounters and summons produce working entities.
An NPC with a spawn delay is hidden and out of the physics world until the delay is over; its components are built then.
NPC levels and experience ​
NpcLevels (runtime_classes/entity/npc_levels.gd) decides the level of an NPC and what it is worth.
- Level.
Entity.initialize_entitytakes the level of the definition (or thelevel_overrideof the placed NPC) and passes it toNpcLevels.scaled_level(npc, base_level, party_manager). That callsGameplayConfig.get_scaled_npc_level(base_level, reference_level, rank_types): withnpc_level_scalingoff, or no party (reference 0), the level is unchanged; anEntityTagDefinitionwithFIXED_OFFSETgivesreference + level_offset(the first one in the NPC's type list),NEVER_SCALESkeeps the level, otherwise the level is raised toreference - scale_up_within_levelsif lower (scale up) or lowered toreference + scale_down_within_levelsif higher (scale down). The result is clamped to1..max_leveland set once;StatsComponent.set_levelthen applies the growth. A saved NPC loads its savedcurrent_level.NpcLevels.reference_levelis the average (rounded), the highest or the current player's level, byscaling_reference. - Experience.
NPC.get_experience_worth()isNpcLevels.kill_experience(npc):GameplayConfig.get_kill_experience(level, fixed_worth)(the worth of the NPC itself inFIXEDmode, or when above 0 in the other modes; else thekill_experience_tablerow with the largest level not above the NPC's, or thekill_experience_formulaevaluated at the level) timesNPCDefinition.experience_multiplier,UniqueEntityData.experience_multiplierand theexperience_multiplierof each entity type, rounded.CombatManageremitsexperience_grant_requestedwith it when the last enemy of a fight that included a player dies;PartyManager.grant_party_experiencegives it to the party and the reserve share to the reserve.NPC.get_fixed_experience_worth()is the raw worth (the override of the placed NPC, else the definition). Withkill_experience_falloffon, the amount is also multiplied byGameplayConfig.get_kill_experience_falloff_factor(reference_level - npc.current_level):1 - clamp(formula(levels_below - kill_experience_falloff_grace), 0, 100) / 100, or 1 at or under the grace. - Rescaling.
NpcLevels.rescale(npc, party_manager)recomputesscaled_level(npc, base_level_of(npc), party)for a living NPC: an NPC in a fight setsrescale_pendingandEntity.exit_combatapplies it; the health share of the master pool is kept;NPC.level_rescaled(old, new)is emitted. Triggers:NPC._respawn_entity(rescale_npcs_on_respawn) andObjectRegistry._on_party_changed, connected (on the first registered entity) toPartyManager.party_levels_changed(a member emittedentity_leveled_up),player_added,player_removedandnew_current_player(rescale_npcs_on_party_change). The registry rescales every NPC only whenNpcLevels.reference_leveldiffers from the one it last scaled to.
Components ​
Reached through entity.components: stats(), effects(), abilities(), equipment(), inventory(), audio(), rig(), animation(), states(), pets(), mediator().
The mediator forwards the signals of the components as the public signals of Entity: entity_taken_damage, entity_hit_dealt, entity_hit_received, entity_ability_cast, effect_gained, entity_healing_applied, entity_leveled_up, equipment_changed, entity_item_used and more. Listen to the entity, not to its components.
The state component ​
EntityStateComponent owns what an NPC (or a controlled-by-AI member) does:
- the behavior script: schedules and tasks, run every
behavior_intervalseconds (the level of detail sets the interval; a paused entity processes nothing), - the combat script, a state machine: Inactive, Target search, Chasing, Attacking, Following, Flee, Disoriented, Incapacitated, Player command, Dead (see Behaviors),
- the movement states (idle, moving, falling, turning, directional, climbing) and the
NavigationController, - three detection areas: pull range, attack range and player detection, sized from the Sight Range stat.
If a definition has no combat script, _create_default_combat_script() makes a simple one.
Hostility ​
FactionDefinition.is_hostile_to, is_friendly_to, is_neutral_to and can_target_as_enemy answer every "who is an enemy?" question. An entity with no faction is neutral. A neutral NPC that is attacked fights back and is neutral again when the fight ends (the temporary hostility of the threat table). See Factions.
Death ​
entity_dying is emitted first (procs run, a resurrection can step in), then entity_died. What happens next depends on the kind:
| Kind | Then |
|---|---|
| NPC | A corpse with a LootInteraction that replaces the living interaction if there is loot (it goes when the corpse is empty or the NPC is resurrected). It respawns after respawn_timer, or is removed with despawn_on_death. A respawn goes through resurrect() |
| Pet | Leaves its summoner (PetManagerComponent.remove_pet) |
| Player | Handled by the party manager, by the death behavior of the Gameplay Config |
| Destructible object | InteractableObject._on_master_pool_depleted: plays destroyed and refuses interaction |
A dead entity leaves combat. Corpses and their loot are saved.
Pets ​
A Pet is an NPC with a summoner. It is registered in the summoner's PetManagerComponent and its DynamicFollowerSystem, which gives each follower a formation position. Following is the FollowingState; the follow task asks the follower system for the spot. A summoned interactable takes its summoner's faction and leaves when the summoner dies.
Players and the party ​
PartyManager holds the active party (players), the reserve, and who is the current player.
| Call | What it does |
|---|---|
get_party_members(), get_main_character() | The active party; slot 0 |
set_current_player(player) | Control passes to a member; every other member gets the state of a companion (refresh_control_state) |
try_switch_to(player) | Switch, or refuse with a reason (switch_denied: not allowed, dead, in combat); switch_to_next(±1) cycles |
recruit_player, move_to_reserve, move_to_party, swap_with_reserve, remove_player, set_max_party_size | Party management; a recruit goes into the party, else the reserve, else is refused. The reserve is saved |
With Has main character off (and character switching allowed) get_main_character() returns null: slot 0 can be moved to the reserve and only a party wipe ends the game. GameplayConfig.main_character_exists() is has_main_character or not allow_character_switching.
A companion follows with FollowingState at companion_follow_distance, joins a fight within companion_assist_range, attacks with the basic attack and (CompanionAttackLogic) its abilities: an enemy-targeting ability on the target, an ally-targeting ability on the most hurt member under 70 %. The main character's death (or the whole party's) ends the game under Game over and Permadeath; a companion's death does not.
Player.get_proficiencies() is the proficiency tracker; levels, experience, skill points and skill trees are saved with the player.
Interactions ​
An InteractableObject (a StaticBody3D) is made from an InteractableDefinition. Its own copy of the Interaction is made on initialization and told which object it belongs to (set_entity_reference, then setup_for_interactable_objects).
process_interaction(entity) is what the interact key calls: the interaction cooldown, the lock (a key in the bag unlocks it, consume_key_on_unlock), then interaction.can_interact and start_interaction. An interaction can implement callbacks: on_locked_reaction, on_unlocked, on_object_destroyed, save_state and load_state, cleanup.
| Base | Works on | Types |
|---|---|---|
InteractableObjectInteraction | Objects | Door, Container, Switch (Light), Ladder, Rabbit Hole, Trap, Readable |
EntityInteraction | Entities | Loot, Join Party |
Interaction | Both | Speak, Conversation, Vendor, Crafting, Grant Quest, Show UI Panel |
A custom interaction is a new script that extends one of the bases. get_interaction_by_type(name) lets one interaction find another (a rabbit hole finds the interaction of its destination).
Saving ​
An entity saves its stats and pools, effects, inventory, equipment, abilities with cooldowns, threat table, position and meta data (Entity.meta_data). A player adds its levels, experience, proficiencies, skill trees and pending rewards. An interactable saves its state (open, on, armed) and not its cooldown.
The classes ​
Definitions ​
| Class | What it is |
|---|---|
| ActionBarLayoutEntry | One planned slot of the action bar of a player class: the ability that belongs on a slot, and whether the player may change that slot. |
| CharacterDefinition | Character Definition - Unique template for creating player characters References a PlayerClassDefinition and inherits visual/audio from EntityDefinition |
| CustomCharacterDefinition | CustomCharacterDefinition - Extended character template with full customization support Stores facial feature configurations, shader color parameters, blend shape weights, and voice selection for creating unique, customizable player characters |
| EntityDefinition | EntityDefinition contains all visual, audio, and display configuration for entities This serves as the base class for NPCDefinition and CharacterDefinition |
| InteractableDefinition | Core data definition for interactable objects. |
| NPCDefinition | NPCDefinition extends EntityDefinition with combat stats, AI behavior, and loot systems Used for creating NPC entities with full combat and inventory capabilities |
| PlayerClassDefinition | PlayerClassDefinition defines the template and progression for player character classes This is a class archetype (like "Warrior", "Mage") not tied to specific entity models |
| TemplateBaseline | What a template was the last time an entity that uses it looked at it: the base values of its stats and pools, its immunities and its abilities. |
| UITagDefinition | An entity tag: a label that has no effect on the entity. |
Interactions ​
| Class | What it is |
|---|---|
| ContainerInteraction | Container interaction - manages inventory storage in world objects Uses InteractableObject's InventoryComponent (created if this interaction is present) |
| ConversationInteraction | Interaction for dialogue/conversations with NPCs Uses the Conversation resource system with ConversationInstance for runtime state |
| CraftingInteraction | Crafting interaction that opens the crafting interface when activated Can be attached to NPCs, Crafting Tables, or other interactive objects Updated to use CraftingJob's existing timer system instead of redundant timers |
| DoorInteraction | Door interaction - opens/closes doors with animations Uses available_animations from InteractableDefinition for animation selection |
| EntityInteraction | Only entities can use these interactions |
| GatherInteraction | A gathering node (an ore vein, an herb, a tree to chop, a fishing spot): using it gives the player what its loot rules of the trigger "On Gathered" roll, straight to the bag. |
| GrantQuestInteraction | Interaction that instantly activates a Quest if player meets requirements |
| InteractableObjectInteraction | Only interactable objects can use these interactions |
| Interaction | Base class for all entity interactions Provides the foundation for different types of NPC interactions |
| JoinPartyInteraction | Interaction grants a new Player to the party, interactee will be a NPC/Object So we will create a Player & optionally disable/hide the Interactee. |
| LadderInteraction | Ladder interaction - climbing system using Path3D Discovers scene structure by name: "LadderPath", "StartMarker", "EndMarker" |
| LightInteraction | Light interaction - extends SwitchInteraction to control lighting Creates Light3D node (OmniLight3D or SpotLight3D) at runtime |
| LootInteraction | Loot Interaction for NPCs Allows players to access a dead entity's inventory Works similarly to InteractableContainer but uses entity.components.inventory() |
| MountInteraction | Lets the player get on this NPC: a horse, a griffin, a cart, a tank, a boat. |
| RabbitHoleInteraction | Rabbit hole teleportation system - supports both local and inter-map teleportation Used by players: local teleportation (same map) and inter-map teleportation (NPCs and pets using a rabbit hole is a future option, through the behaviour tasks) |
| ReadableInteraction | Readable interaction - displays multi-page text content in UI panel Used for signs, books, plaques, notes, etc. |
| ShowUIPanelInteraction | Opens a panel of the interface when the NPC or the object is used: a wardrobe that opens the inventory, a notice board that opens a bounty panel of your own, a mirror that opens the character sheet. |
| SpeakInteraction | Simple interaction that displays text and optionally plays a voice line |
| SwitchInteraction | Switch interaction - handles ON/OFF toggle with lock mechanics and audio feedback Base class for LightInteraction and other toggle-based interactions |
| TrainerInteraction | A trainer: using the NPC or the object opens a list of lessons that the player can buy (abilities, ranks, proficiency levels, professions, tiers, specializations, recipes). |
| TrapInteraction | Trap interaction - triggers effects through proximity, interaction, or events Integrates with combat system through effect application |
| VendorInteraction | Vendor interaction that opens the shop interface when activated |
Entities (runtime) ​
| Class | What it is |
|---|---|
| ActionBarSlotData | Data structure for storing action bar slot content Can reference either abilities or items REFACTORED: Now stores direct item instance references instead of inventory indices |
| DynamicFollowerSystem | DynamicFollowerSystem manages a group of followers in a dynamic formation around a leader. |
| Entity | Entity is the base class for all characters and creatures in the game world. |
| EntityComponentMediator | Internal signal bus for Entity component coordination |
| EntityComponentRegistry | Unified component manager for Entity - combines registry and factory Provides type-safe access to all entity components with lazy initialization Eliminates timing issues by ensuring components exist when accessed |
| EntityTemplates | Entities that follow a template. |
| FormationSystem | Places the party members around a target position in a formation (tight, spread, V, line or wedge): calculate_formation_positions answers with a position for every unit, with a base spacing and some randomness. |
| InteractableObject | Unified interactable object class - uses InteractableDefinition + Interactions All specialized logic is now in Interaction subclasses |
| MountCrew | The AI crew of a vehicle: it keeps a ride (a MountSession with no rider) on every seat that has an AI that acts when the seat is empty, so a tank drives and shoots by itself without any NPC sitting in it. |
| MountSession | One rider on one seat. |
| MovementClaim | What something asks of the movement of an entity: a movement volume that is around it (water, a weightless room), an effect that lets it fly. |
| NPC | NPC represents a non-player character in the game. |
| NpcLevels | The level of an NPC and the experience it gives, by the settings of the project (Gameplay Config: NPC Level Scaling and Kill Experience). |
| PartyManager | PartyManager manages the physical containers and setup for the player party system. |
| Pet | Pet represents a summoned creature or Player controlled by an AI. |
| PetManagerComponent | PetManagerComponent manages the pets owned by an entity. |
| Player | Player represents a player-controlled character in the game. |