Knowndynamiclocations
Based on game build 714014 | Last updated: 2026-03-03
Overview
KnownDynamicLocations is a component that stores and manages named dynamic position references relative to walkable platforms or absolute world space. It allows entities to remember and retrieve positions with optional platform attachment (e.g., for floating structures) and supports loading, saving, and handling platform removal events. It integrates with DST’s dynamic position system and worldgen lifecycle hooks (POPULATING, LoadPostPass).
This component is typically attached to entities that need to persist spatial references (like beehives, beefalo pens, or procedural structures) across save/load cycles and platform changes.
Usage example
local inst = CreateEntity()
inst:AddComponent("knowndynamiclocations")
-- Remember a new location named "spawner_pos"
inst.components.knowndynamiclocations:RememberLocation("spawner_pos", Vector3(10, 0, 20))
-- Retrieve the stored position as a Vector3
local pos = inst.components.knowndynamiclocations:GetLocation("spawner_pos")
-- Store additional locations as needed
inst.components.knowndynamiclocations:RememberLocation("exit_pos", Vector3(-5, 0, 15), true) -- dont_overwrite = true
-- Cleanup on removal
inst:RemoveComponent("knowndynamiclocations")
Dependencies & tags
Components used: None identified
Tags: None identified
Properties
No public properties.
Main functions
GetLocation(name)
- Description: Returns the absolute world-space position of a remembered location as a
Vector3. Returnsnilif the name is not found. - Parameters:
name(string) – the identifier used when remembering the location. - Returns:
Vector3?– world-space position ornil.
GetDynamicLocation(name)
- Description: Returns the raw
DynamicPositionobject for a remembered location (enabling platform-aware position updates). Returnsnilif the name is not found. - Parameters:
name(string) – the identifier used when remembering the location. - Returns:
DynamicPosition?– dynamic position object ornil.
RememberLocation(name, pt, dont_overwrite)
- Description: Records a new position
ptunder the givenname. Ifdont_overwriteistrue, it does not overwrite an existing entry; otherwise, any prior entry is removed first. Handles deferred loading (POPULATING) and automatic platform attachment. - Parameters:
name(string) – unique identifier for the location.
pt(Vector3) – position coordinates (x, y, z). Must be valid numbers (non-NaN/Inf).
dont_overwrite(boolean, optional) – iftrue, preserves existing entry; defaults tofalse. - Returns: Nothing.
- Error states: Throws an error if
ptcontains invalid numeric values (e.g.,NaN,Inf).
ForgetLocation(name)
- Description: Removes a remembered location by name, unsubscribing from any associated platform removal events.
- Parameters:
name(string) – the identifier of the location to forget. - Returns: Nothing.
OnSave()
- Description: Serializes all remembered locations into a data table suitable for saving. Excludes entries if none exist.
- Parameters: None.
- Returns:
{ locations = { { name = "string", x = number, y = number?, z = number } } }ornil.
OnLoad(data)
- Description: Reconstructs remembered locations from saved data. Clears prior entries before reloading.
- Parameters:
data(table) – the saved data table containing alocationsarray. - Returns: Nothing.
LoadPostPass(ents, data)
- Description: Called during post-load initialization to finalize platform-relative positions deferred during initial load (
POPULATINGstate). Converts staticlocal_ptpositions into fullDynamicPositionobjects and attaches platform listeners. - Parameters:
ents(table) – entity mapping for resolution (unused in current implementation).
data(table) – loaded data (unused in current implementation). - Returns: Nothing.
GetDebugString()
- Description: Returns a human-readable string listing all remembered locations and their
DynamicPositionrepresentations. Returnsnilif no locations exist. - Parameters: None.
- Returns:
string?– formatted debug string ornil.
OnRemoveFromEntity()
- Description: Called when the component is removed from its entity. Stops watching all registered platforms to prevent dangling event callbacks.
- Parameters: None.
- Returns: Nothing.
Events & listeners
- Listens to:
onremove– registered per-platform entry to detect when a walkable platform is removed, updating the stored position to world-space absolute coordinates. - Pushes: None identified.