Prototyper
Based on game build 714014 | Last updated: 2026-03-03
Overview
Prototyper is a component responsible for managing the activation state of crafting stations that support prototype unlocking (e.g., workbenches, altars). It tracks which entities (doers) have activated the station, maintains associated tech trees, and handles lifecycle events such as activation/deactivation and recipe crafting. It is typically attached to prefabs that serve as crafting stations with unlockable recipes.
Usage example
local inst = CreateEntity()
inst:AddComponent("prototyper")
inst.components.prototyper.onturnon = function(inst)
print("Prototyper turned on")
end
inst.components.prototyper.onturnoff = function(inst)
print("Prototyper turned off")
end
inst.components.prototyper.onactivate = function(inst, doer, recipe)
print("Recipe " .. recipe.name .. " crafted by " .. Doer:GetDebugString())
end
inst.components.prototyper:TurnOn(some_doer)
Dependencies & tags
Components used: craftingstation (optional; used in Activate to update recipe crafting limits)
Tags: Adds prototyper to the host entity on construction; removes it on removal.
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
trees | table | TechTree.Create() | Internal tech trees data structure representing unlocked prototypes. |
on | boolean | false | Whether the prototyper is currently active (i.e., has at least one doer). |
onturnon | function | nil | Optional callback fired when the prototyper transitions from inactive to active (no doers → ≥1 doer). |
onturnoff | function | nil | Optional callback fired when the prototyper transitions from active to inactive (≥1 doer → no doers). |
onturnonfordoer | function | nil | Optional per-doer callback fired when a specific doer turns the prototyper on. |
onturnofffordoer | function | nil | Optional per-doer callback fired when a specific doer turns the prototyper off. |
onactivate | function | nil | Optional callback fired when Activate() is called (e.g., when a recipe is crafted at the station). |
doers | table | {} | Map of active doers (entity → true). Used to track who has activated the station. |
Main functions
TurnOn(doer)
- Description: Registers a doer as having activated this prototyper. If this is the first doer, also triggers the global
onturnoncallback and setson = true. - Parameters:
doer(entity) - The entity turning the prototyper on. - Returns: Nothing.
- Error states: No effect if
doeris already registered.
TurnOff(doer)
- Description: Removes the doer’s activation. If this was the last doer, triggers the global
onturnoffcallback and setson = false. - Parameters:
doer(entity) - The entity turning the prototyper off. - Returns: Nothing.
- Error states: No effect if
doeris not currently registered.
GetTechTrees()
- Description: Returns a deep copy of the internal tech trees table.
- Parameters: None.
- Returns: table — A copy of
self.trees, safe for external modification. - Error states: None.
Activate(doer, recipe)
- Description: Reports that a recipe was crafted at this prototyper. Invokes
craftingstation:RecipeCrafted(if present) to decrement the recipe’s craft limit, and fires theonactivatecallback. - Parameters:
doer(entity) — The entity that crafted the recipe.
recipe(table) — The recipe object, expected to have at least anamefield (recipe.name). - Returns: Nothing.
- Error states: If
craftingstationis absent, the recipe limit logic is skipped; otherwise the call proceeds normally.
Events & listeners
- Listens to:
onremove— Used to automaticallyTurnOffa doer if it is removed from the world while still registered as an active doer. Callback registered per doer. - Pushes: None.