Constructionplans
Based on game build 714014 | Last updated: 2026-03-03
Overview
ConstructionPlans maintains a mapping between target prefabs and their associated construction site prefabs. When a construction action is initiated, this component looks up the target prefab and spawns the corresponding construction site, replacing the original entity. It is typically attached to player entities or handheld items (e.g., blueprints) and works in conjunction with the constructionsite component.
Usage example
local inst = CreateEntity()
inst:AddComponent("constructionplans")
inst.components.constructionplans:AddTargetPrefab("campfire", "campfire_fire")
inst.components.constructionplans:AddTargetPrefab("foundation", "foundation_plans")
-- Later, when targeting an existing campfire:
inst.components.constructionplans:StartConstruction(target_entity)
Dependencies & tags
Components used: constructionsite (via target.components.constructionsite check)
Tags: Dynamically adds/removes <prefab>_plans tags (e.g., campfire_plans) to track known blueprint mappings.
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
targetprefabs | table | {} | Maps source prefab names (string) to their corresponding construction site prefab names (string). |
Main functions
AddTargetPrefab(prefab, constructionprefab)
- Description: Registers a mapping from a target prefab (e.g.,
"campfire") to its construction site prefab (e.g.,"campfire_fire"). Adds a tag<prefab>_plansif not already present. - Parameters:
prefab(string) – name of the existing entity prefab that can be replaced.
constructionprefab(string) – name of the construction site prefab to spawn in its place. - Returns: Nothing.
- Error states: None. Duplicate registrations for the same
prefabare silently overwritten.
RemoveTargetPrefab(prefab)
- Description: Removes the mapping for a given prefab and removes its associated
<prefab>_planstag. - Parameters:
prefab(string) – name of the prefab whose mapping should be removed. - Returns: Nothing.
- Error states: No effect if the prefab has no mapping.
StartConstruction(target)
- Description: Attempts to spawn a construction site in place of the given
targetentity, based on the registered mapping fortarget.prefab. Removes the original entity and notifies the new site of construction start. - Parameters:
target(entity) – the existing entity to be replaced by a construction site. - Returns:
product(entity ornil) – the newly spawned construction site, ornilif construction fails. - Error states:
- Returns
nil, "MISMATCH"if no mapping exists fortarget.prefab. - Returns
nilif the target already has aconstructionsitecomponent (prevents double-construction). - Returns
nilsilently ifSpawnPrefabfails.
- Returns
OnRemoveFromEntity()
- Description: Cleanup callback invoked when the component is removed from its entity. Removes all
<prefab>_planstags added byAddTargetPrefab. - Parameters: None.
- Returns: Nothing.
Events & listeners
- Listens to: None.
- Pushes: The component itself does not push events; however,
StartConstructioncallsproduct:PushEvent("onstartconstruction")on the spawned construction site entity.