Constructionplans
Overview
This component allows an entity to define and manage a set of "construction plans," specifying which source prefabs can be transformed into particular construction prefabs. It facilitates the in-game process of initiating construction on a target entity, removing the original, and spawning a new construction site. It also handles associated tagging for the parent entity.
Dependencies & Tags
None identified.
This component adds tags of the format [prefab]_plans to its parent entity for each registered prefab in targetprefabs. These tags are removed upon unregistering a prefab or when the component is removed from the entity.
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
inst | Entity | self | A reference to the entity this component is attached to. |
targetprefabs | table | {} | A table mapping target prefab names (string) to their corresponding construction prefab names (string). |
Main Functions
AddTargetPrefab(prefab, constructionprefab)
- Description: Registers a new target prefab and its corresponding construction prefab. If the
prefabis new, it also adds a tag in the format[prefab]_plansto the component's parent entity. - Parameters:
prefab(string): The name of the prefab that can be transformed.constructionprefab(string): The name of the prefab that should be spawned as the construction site.
RemoveTargetPrefab(prefab)
- Description: Unregisters a target prefab. If the
prefabwas registered, it removes the associated[prefab]_planstag from the component's parent entity. - Parameters:
prefab(string): The name of the prefab to unregister.
StartConstruction(target)
- Description: Initiates the construction process by transforming a
targetentity into its designated construction prefab. It first checks if the target is valid and does not already have aconstructionsitecomponent. If a validconstructionprefabis found for the target's prefab, it spawns the construction product at the target's world position, removes the originaltargetentity, and pushes an "onstartconstruction" event on the new product. - Parameters:
target(Entity): The entity to be transformed into a construction site.
- Returns:
product(Entity): The newly spawned construction prefab, ornilif the process failed."MISMATCH"(string): If the target's prefab is not registered within this component'stargetprefabs.
OnRemoveFromEntity()
- Description: This callback is invoked when the
ConstructionPlanscomponent is removed from its parent entity. It iterates through all registered target prefabs and removes their corresponding[prefab]_planstags from the parent entity to ensure proper cleanup. - Parameters: None.
Events & Listeners
- Pushes:
"onstartconstruction": Triggered on the newly spawned construction product after a successfulStartConstructioncall.