Vaultroom
Based on game build 722832 | Last updated: 2026-04-28
Overview
Vaultroom manages the lifecycle of virtual dungeon rooms that can be dynamically created, saved, and loaded. It handles terraforming at the room location, spawning room-specific entities from definitions, and cleaning up entities when the room is unloaded. This component is essential for instanced dungeon areas where entities need to persist across player visits without cluttering the global entity space.
Usage example
local inst = CreateEntity()
inst:AddComponent("vaultroom")
-- Create a new room from definition
inst.components.vaultroom:LayoutNewRoom("vault_room_01")
-- Save and unload the room (returns save data)
local save_data, remaining_ents = inst.components.vaultroom:UnloadRoom(true)
-- Later, load the room from saved data
inst.components.vaultroom:LoadRoom("vault_room_01", save_data)
-- Get current room ID
local roomid = inst.components.vaultroom:GetCurrentRoomId()
Dependencies & tags
External dependencies:
prefabs/vaultroom_defs-- room definition table containing layout and terraform functions
Components used:
spell-- checkstargetto trace entity ownership chain during unloadformationleader-- checkstargetto trace entity ownership chain during unloadfollower-- callsGetLeader()to trace entity ownership chain during unloadinventoryitem-- checksownerto trace entity ownership chain during unloadinventory-- callsDropEverythingWithTag()during unload cleanupcontainer-- callsDropEverythingWithTag()during unload cleanup
Tags:
INLIMBO-- excluded from entity search during unloadstaysthroughvirtualrooms-- entities with this tag are skipped during unloadirreplaceable-- entities with this tag are kept, not saved or removedfollowsthroughvirtualrooms-- entities with this tag are kept during unload
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
inst | entity | --- | The entity instance that owns this component. |
roomid | string | nil | Current room definition ID. Set when room is layouted or loaded. |
SAVE_RADIUS | constant (local) | 28 | Search radius for finding entities to save/remove during unload. |
SAVE_NO_TAGS | constant (local) | { "INLIMBO" } | Tags to exclude when searching for entities during unload. |
SAVE_CONTAINER_TAGS | constant (local) | { "_inventory", "_container" } | Tags used to find container entities for dropping irreplaceable items. |
_SKIP | constant (local) | 1 | Action code for entities to ignore during unload (invalid, parented, or staysthroughvirtualrooms). |
_SAVE | constant (local) | 2 | Action code for entities to save/remove during unload. |
_KEEP | constant (local) | 3 | Action code for entities to retain during unload (players, irreplaceable, followsthroughvirtualrooms). |
Main functions
GetCurrentRoomId()
- Description: Returns the current room definition ID. Returns
nilif no room is active. - Parameters: None
- Returns: string room ID or
nil - Error states: None
LayoutNewRoom(id)
- Description: Creates a new room from the given definition ID. Calls terraform and layout functions from
vaultroom_defs. Behavior depends on definition flags: ifdef.TerraformRoomAtXZexists, calls custom terraform; otherwise callsResetTerraformRoomAtXZ. Ifdef.LayoutNewRoomAtXZexists, calls custom layout logic; otherwise skips layout phase. SetsPOPULATING = trueduring processing. - Parameters:
id-- string room definition key fromvaultroom_defs
- Returns: nil
- Error states: Errors via
assert()ifself.roomidis already set (room already exists). Errors viaassert(false)ifdefs[id]is nil (invalid room ID).
UnloadRoom(save)
- Description: Unloads all entities in the room. If
saveis true, collects save records for persisting entities and returns save data. Entities are categorized as_SKIP(ignore),_SAVE(save/remove), or_KEEP(retain). Drops irreplaceable items from containers before removal. SetsPOPULATING = trueduring processing. - Parameters:
save-- boolean; if true, generates save data instead of just removing entities
- Returns: Table with save data (if
saveis true), ornil; plus table of remaining entities that weren't saved/removed - Error states: None. Returns early if
defs[self.roomid]is nil.
ResetRoom()
- Description: Resets the room to its initial state. Calls
UnloadRoom()to clear existing entities, then callsResetTerraformRoomAtXZto restore terrain. - Parameters: None
- Returns: nil
- Error states: None. Silently returns if
self.roomidis nil.
LoadRoom(id, data)
- Description: Loads a room from save data. If
datais nil, callsLayoutNewRoom()for fresh generation. Otherwise spawns saved entities viaSpawnSaveRecord(), hooks up references viaLoadPostPass(), and applies time delta viaLongUpdate()ifworld_timeis present. SetsPOPULATING = trueduring spawn. - Parameters:
id-- string room definition key fromvaultroom_defsdata-- save data table fromUnloadRoom()ornilfor fresh layout
- Returns: nil
- Error states: Errors via
assert()ifself.roomidis already set. Errors viaassert(false)ifdefs[id]is nil.
OnSave()
- Description: Save lifecycle hook. Returns a table containing the current
roomidif set, ornilif no room is active. - Parameters: None
- Returns: Table
{ room = roomid }ornil - Error states: None
OnLoad(data)
- Description: Load lifecycle hook. Restores
roomidfrom saved data. Does not automatically spawn entities — callLoadRoom()separately after this. - Parameters:
data-- save data table fromOnSave()
- Returns: nil
- Error states: None. Handles
databeing nil gracefully.
_inroom(ent, map, tile_x, tile_y) (local)
- Description: Checks if an entity is within the room bounds. Returns true if entity is within 5 tiles of the center OR if the tile is
VAULTorIMPASSABLEwith visual ground. - Parameters:
ent-- entity to checkmap-- world map instancetile_x-- center tile X coordinatetile_y-- center tile Y coordinate
- Returns: boolean
- Error states: None
_getunloadaction(ent, map, tile_x, tile_y) (local)
- Description: Determines what action to take on an entity during unload. Traces ownership chain through
spell.target,formationleader.target,follower:GetLeader(), andinventoryitem.owner. Returns_SKIPfor invalid/parented entities or those withstaysthroughvirtualrooms. Returns_KEEPfor players or entities withirreplaceable/followsthroughvirtualroomstags. Returns_SAVEfor normal room entities. - Parameters:
ent-- entity to evaluatemap-- world map instancetile_x-- center tile X coordinatetile_y-- center tile Y coordinate
- Returns: Number:
_SKIP(1),_SAVE(2), or_KEEP(3) - Error states: None
Events & listeners
None identified. This component does not register any event listeners, push any events, or watch world state variables.