Occupiable
Based on game build 714014 | Last updated: 2026-03-03
Overview
Occupiable enables an entity to be occupied by another entity that has an occupier component. It manages state transitions between empty and occupied, updates entity tags (occupied and occupanttype + "_occupiable"), registers callbacks for when the occupant perishes or is removed, and persists the occupant. It works in conjunction with the occupier component on the occupant entity to coordinate ownership and behavior.
Usage example
local inst = CreateEntity()
inst:AddComponent("occupiable")
-- Configure acceptable occupant type (e.g., "beefalo")
inst.components.occupiable:SetOccupantType("beefalo")
-- Later, when an entity with tag "beefalo" and an `occupier` component approaches:
if inst.components.occupiable:CanOccupy(behemoth) then
inst.components.occupiable:Occupy(behemoth)
end
Dependencies & tags
Components used: occupier, inventoryitem
Tags: Adds/removes occupied; conditionally adds/removes {occupanttype}_occupiable (e.g., beefalo_occupiable) based on occupanttype and occupancy state.
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
occupant | Entity or nil | nil | The entity currently occupying this entity. |
occupanttype | string or nil | nil | Tag name the occupier must possess (e.g., "beefalo") to qualify for occupancy. |
onoccupied | function(inst, occupier) or nil | nil | Optional callback fired when occupation succeeds. |
onemptied | function(inst) or nil | nil | Optional callback fired when the occupant leaves (via Harvest, perished, or removal). |
onperishfn | function(inst, occupier) or nil | nil | Optional callback fired when the occupant perishes while occupied. |
Main functions
IsOccupied()
- Description: Checks whether the entity is currently occupied.
- Parameters: None.
- Returns:
boolean—trueif an occupant is present,falseotherwise.
GetOccupant()
- Description: Returns the entity currently occupying this entity.
- Parameters: None.
- Returns:
Entityornil— the occupant entity, ornilif unoccupied.
CanOccupy(occupier)
- Description: Determines if the given entity can legally occupy this entity.
- Parameters:
occupier(Entity) — the potential occupier entity. - Returns:
boolean—trueif the occupier has the required tag (occupanttype), has anoccupiercomponent, and this entity is currently unoccupied;falseotherwise.
Occupy(occupier)
- Description: Claims the entity for occupation by the given occupier.
- Parameters:
occupier(Entity) — the entity to occupy this one; must satisfyCanOccupy. - Returns:
boolean—trueif occupation succeeds;nilif preconditions fail. - Error states: Returns
nilif already occupied,occupierisnil, oroccupierlacks theoccupiercomponent.
Harvest()
- Description: Releases the occupant (e.g., for pickup or reuse) without destroying it.
- Parameters: None.
- Returns:
Entityornil— the released occupant entity, ornilif unoccupied or the occupant lacksinventoryitem. - Error states: Does not call
perishedoronremovecallbacks; assumes intentional release.
OnSave()
- Description: Returns serialization data for network/save compatibility.
- Parameters: None.
- Returns:
table— e.g.,{ occupant = { save_record } }, or{ occupant = nil }.
OnLoad(data, newents)
- Description: Restores occupancy state during world load or network sync.
- Parameters:
data(table) — data returned byOnSave().
newents(table) — map of restored entity records to instances. - Returns: Nothing.
SetOccupantType(occupanttype)
- Description: (Inferred from tag manipulation logic) Sets the
occupanttypeand updates tags accordingly. Not explicitly defined in this file, but implied byonoccupanttypecallback andCanOccupy. - Parameters:
occupanttype(stringornil) — tag name required of occupiers (e.g.,"beefalo"), ornilto clear restriction. - Returns: Nothing.
Events & listeners
- Listens to:
perished— triggers occupant cleanup viaoccupier.occupiableonperish.
onremove— triggers occupant cleanup viaoccupier.occupiableonremove. - Pushes: Not directly responsible for pushing events, but sets callbacks (
onoccupied,onemptied,onperishfn) that may be defined externally and used to trigger further logic.