Cookable
Based on game build 714014 | Last updated: 2026-03-03
Overview
Cookable allows an entity to be processed into a new cooked item via cooking devices (e.g., campfire, crock pot). It stores the product definition (either a static prefab name or a factory function) and handles the creation of the output item upon cooking. When applied to an entity, it adds the cookable tag and registers a callback function that executes during the cooking process. It optionally synchronizes perishability from the original item to the cooked product, reducing spoilage by half for non-small-creature items.
This component is typically added to raw food prefabs and interacts with the perishable component to preserve freshness in the cooked output.
Usage example
local inst = CreateEntity()
inst:AddComponent("cookable")
inst.components.cookable:SetProduct(" cooked_item_name")
inst.components.cookable:SetOnCookedFn(function(inst, cooker, chef)
-- custom logic (e.g., sound, effects)
end)
Dependencies & tags
Components used: perishable (read-only access via GetPercent/SetPercent for spoilage transfer)
Tags: Adds cookable tag to the entity on initialization; removes it on component removal.
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
product | string or function | nil | The prefab name or a callable that returns a prefab name/function for the cooked result. |
oncooked | function | nil | Optional callback invoked when cooking completes; signature: fn(inst, cooker, chef). |
Main functions
SetOnCookedFn(fn)
- Description: Sets the callback function executed during cooking. Useful for side effects like particle effects, sounds, or custom logic.
- Parameters:
fn(function) — A function accepting three arguments: the cooked entity (inst), the cooking device (cooker), and the cooking character (chef). - Returns: Nothing.
- Error states: No validation; setting
nildisables the callback.
Cook(cooker, chef)
- Description: Performs the cooking action. Executes the
oncookedcallback (if set), spawns the product prefab, and—if both original and product haveperishablecomponents and the item is not asmallcreature—adjusts the product's spoilage level based on the original’s freshness. - Parameters:
cooker(Entity) — The cooking device or appliance used.chef(Entity) — The character performing the cooking.
- Returns:
Entity?— The newly spawned product entity, ornilif no product is defined or spawn fails. - Error states:
- Returns
nilifself.productisnil. - Spoilage transfer is skipped if
self.inst:HasTag("smallcreature")is true, or if either entity lacks aperishablecomponent.
- Returns
Events & listeners
- Pushes: No events are fired by this component itself. Event-driven behavior is expected via the
oncookedcallback.