Inventory
Based on game build 722832 | Last updated: 2026-04-28
Overview
Inventory is the master component that manages an entity's item slots, equipment, and inventory state. On player entities in master simulation, it spawns an inventory_classified prefab to hold netvars for client synchronization. It forwards inventory events (item get/lose, equip/unequip) to the classified entity so clients can mirror the state. Most methods check self.inst.components.inventory to delegate to an underlying inventory component, or fall back to classified entity queries on clients.
Usage example
-- Check inventory state:
if inst.components.inventory ~= nil then
local active_item = inst.components.inventory:GetActiveItem()
local is_visible = inst.components.inventory:IsVisible()
local is_heavy = inst.components.inventory:IsHeavyLifting()
end
-- Master-side state mutation:
if TheWorld.ismastersim and inst.components.inventory ~= nil then
inst.components.inventory:SetHeavyLifting(true)
inst.components.inventory:OnOpen()
end
Dependencies & tags
External dependencies:
inventory_classified-- prefab spawned on master to hold netvars for client synchronization
Components used:
inventory-- underlying inventory component; this component delegates most calls to it when presentplayeractionpicker-- pushes/pops action filters when heavy lifting or floater held state changesrevivablecorpse-- checked during OpenInventory to hide inventory for corpses
Tags:
corpse-- checked during OpenInventory; hides inventory if entity has this tag
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
opentask | task | nil | Scheduled task for opening inventory; cancelled on close/remove. |
classified | entity | nil | The classified entity holding netvars; spawned on master, attached on client. |
ondetachclassified | function | nil | Callback registered on classified entity onremove event. Signature: fn(). Set internally by AttachClassified(). |
Main functions
Constructor (self, inst)
- Description: Initializes the inventory component. On master simulation with player entities, spawns
inventory_classifiedprefab and sets up event listeners to forward inventory changes to clients. On clients, attaches to existing classified entity frominst.inventory_classified. - Parameters:
inst-- the owning entity instance
- Returns: nil
- Error states: None.
OnRemoveEntity()
- Description: Cleanup handler called when the entity is removed. Cancels open task on master, closes inventory, removes classified entity. On client, detaches classified and removes event callbacks.
- Parameters: None.
- Returns: nil
- Error states: Errors if
inst.components.inventoryis nil (no guard before:Close()call).
AttachClassified(classified)
- Description: Attaches a classified entity to this component. Registers listeners for
visibledirty,heavyliftingdirty, andfloaterhelddirtyevents. Sets uponremovecallback to auto-detach. Triggers initial visibility check. - Parameters:
classified-- the classified entity to attach
- Returns: nil
- Error states: None.
DetachClassified()
- Description: Detaches the classified entity. Clears references, hides inventory UI, pushes
newactiveitemandinventoryclosedevents. - Parameters: None.
- Returns: nil
- Error states: None.
OnOpen()
- Description: Sets classified target to the owning entity and sets
visiblenetvar totrue. Called when inventory opens. - Parameters: None.
- Returns: nil
- Error states: None.
OnClose()
- Description: Cancels open task, sets classified target to itself, sets
visiblenetvar tofalse. Called when inventory closes. - Parameters: None.
- Returns: nil
- Error states: None.
OnShow()
- Description: Sets
visiblenetvar totruewithout changing classified target. Used to show inventory without full open state. - Parameters: None.
- Returns: nil
- Error states: None.
OnHide()
- Description: Sets
visiblenetvar tofalsewithout changing classified target. Used to hide inventory without full close state. - Parameters: None.
- Returns: nil
- Error states: None.
SetHeavyLifting(heavylifting)
- Description: Sets the
heavyliftingnetvar on classified entity and triggers immediate filter update via_OnHeavyLiftingDirty. - Parameters:
heavylifting-- boolean indicating if entity is heavy lifting
- Returns: nil
- Error states: None.
SetFloaterHeld(floaterheld)
- Description: Sets the
floaterheldnetvar on classified entity and triggers immediate filter update via_OnFloaterHeldDirty. - Parameters:
floaterheld-- boolean indicating if entity is holding a floater
- Returns: nil
- Error states: None.
GetNumSlots()
- Description: Returns the number of inventory slots. Delegates to
inst.components.inventory:GetNumSlots()if present, otherwise usesGetMaxItemSlots()based on game mode. - Parameters: None.
- Returns: number of slots
- Error states: None.
CanTakeItemInSlot(item, slot)
- Description: Validates if an item can be placed in a specific slot. Checks item's
inventoryitemreplica, container rules, game mode properties, slot bounds, and existing item lock/stack status. - Parameters:
item-- entity to checkslot-- integer slot index
- Returns: boolean
- Error states: None.
AcceptsStacks()
- Description: Returns whether this inventory accepts item stacking. Delegates to
inst.components.inventory:AcceptsStacks()if present, otherwise returnstrue. - Parameters: None.
- Returns: boolean
- Error states: None.
IgnoresCanGoInContainer()
- Description: Returns whether this inventory ignores container placement rules. Delegates to
inst.components.inventory:IgnoresCanGoInContainer()if present, otherwise returnsfalse. - Parameters: None.
- Returns: boolean
- Error states: None.
EquipHasTag(tag)
- Description: Checks if any equipped item has the specified tag. Delegates to
inst.components.inventory:EquipHasTag()if present, otherwise checks classified equips. - Parameters:
tag-- string tag to check
- Returns: boolean
- Error states: None.
IsHeavyLifting()
- Description: Returns whether the entity is currently heavy lifting. Delegates to
inst.components.inventory:IsHeavyLifting()if present, otherwise readsheavyliftingnetvar from classified. - Parameters: None.
- Returns: boolean
- Error states: None.
IsFloaterHeld()
- Description: Returns whether the entity is holding a floater item. Delegates to
inst.components.inventory:IsFloaterHeld()if present, otherwise readsfloaterheldnetvar from classified. - Parameters: None.
- Returns: boolean
- Error states: None.
IsVisible()
- Description: Returns whether the inventory UI is currently visible. Delegates to
inst.components.inventory.isvisibleif present, otherwise readsvisiblenetvar from classified. - Parameters: None.
- Returns: boolean
- Error states: None.
IsOpenedBy(guy)
- Description: Returns whether the inventory is opened by the specified entity. Delegates to
inst.components.inventory:IsOpenedBy()if present, otherwise checks visibility and entity match. - Parameters:
guy-- entity to check
- Returns: boolean
- Error states: None.
IsHolding(item, checkcontainer)
- Description: Returns whether the inventory is holding the specified item. Delegates to
inst.components.inventory:IsHolding()if present, otherwise uses classifiedIsHolding(). - Parameters:
item-- entity to checkcheckcontainer-- boolean to include containers in check
- Returns: boolean
- Error states: None.
FindItem(fn)
- Description: Finds an item matching the predicate function. Delegates to
inst.components.inventory:FindItem()if present, otherwise uses classifiedFindItem(). - Parameters:
fn-- predicate function taking item as argument
- Returns: entity or
nil - Error states: None.
GetActiveItem()
- Description: Returns the currently active (held) item. Delegates to
inst.components.inventory:GetActiveItem()if present, otherwise uses classifiedGetActiveItem(). - Parameters: None.
- Returns: entity or
nil - Error states: None.
GetItemInSlot(slot)
- Description: Returns the item in the specified slot. Delegates to
inst.components.inventory:GetItemInSlot()if present, otherwise uses classifiedGetItemInSlot(). - Parameters:
slot-- integer slot index
- Returns: entity or
nil - Error states: None.
GetEquippedItem(eslot)
- Description: Returns the item in the specified equip slot. Delegates to
inst.components.inventory:GetEquippedItem()if present, otherwise uses classifiedGetEquippedItem(). - Parameters:
eslot-- integer equip slot index
- Returns: entity or
nil - Error states: None.
GetItems()
- Description: Returns all items in inventory slots. Delegates to
inst.components.inventory.itemslotsif present, otherwise uses classifiedGetItems(). - Parameters: None.
- Returns: table of items
- Error states: None.
GetEquips()
- Description: Returns all equipped items. Delegates to
inst.components.inventory.equipslotsif present, otherwise uses classifiedGetEquips(). - Parameters: None.
- Returns: table of equipped items
- Error states: None.
GetOpenContainers()
- Description: Returns a table of open container entities as keys (values are
true). Delegates toinst.components.inventory.opencontainersif present, otherwise builds from HUD controls. - Parameters: None.
- Returns: table
- Error states: None.
GetOverflowContainer()
- Description: Returns the overflow container (backpack). Delegates to
inst.components.inventory:GetOverflowContainer()if present, otherwise uses classifiedGetOverflowContainer(). - Parameters: None.
- Returns: container or
nil - Error states: None.
IsFull()
- Description: Returns whether the inventory is full. Delegates to
inst.components.inventory:IsFull()if present, otherwise uses classifiedIsFull(). - Parameters: None.
- Returns: boolean
- Error states: None.
Has(prefab, amount, checkallcontainers)
- Description: Checks if inventory has the specified prefab with required amount. Delegates to
inst.components.inventory:Has()if present, otherwise uses classifiedHas(). - Parameters:
prefab-- string prefab nameamount-- number requiredcheckallcontainers-- boolean to include containers
- Returns: boolean, number found
- Error states: None.
HasItemWithTag(tag, amount)
- Description: Checks if inventory has items with the specified tag. Delegates to
inst.components.inventory:HasItemWithTag()if present, otherwise uses classifiedHasItemWithTag(). - Parameters:
tag-- string tag to checkamount-- number required
- Returns: boolean, number found
- Error states: None.
ReturnActiveItem()
- Description: Returns the active item to its slot. Delegates to
inst.components.inventory:ReturnActiveItem()if present, otherwise uses classifiedReturnActiveItem(). - Parameters: None.
- Returns: nil
- Error states: None.
PutOneOfActiveItemInSlot(slot)
- Description: Moves one item from active item to the specified slot. Delegates to
inst.components.inventory:PutOneOfActiveItemInSlot()if present, otherwise uses classified. - Parameters:
slot-- integer slot index
- Returns: nil
- Error states: None.
PutAllOfActiveItemInSlot(slot)
- Description: Moves all of active item to the specified slot. Delegates to
inst.components.inventory:PutAllOfActiveItemInSlot()if present, otherwise uses classified. - Parameters:
slot-- integer slot index
- Returns: nil
- Error states: None.
TakeActiveItemFromHalfOfSlot(slot)
- Description: Takes half of the item from the specified slot into active item. Delegates to
inst.components.inventory:TakeActiveItemFromHalfOfSlot()if present, otherwise uses classified. - Parameters:
slot-- integer slot index
- Returns: nil
- Error states: None.
TakeActiveItemFromCountOfSlot(slot)
- Description: Takes a specific count from the specified slot into active item. Delegates to
inst.components.inventory:TakeActiveItemFromCountOfSlot()if present, otherwise uses classified. - Parameters:
slot-- integer slot index
- Returns: nil
- Error states: None.
TakeActiveItemFromAllOfSlot(slot)
- Description: Takes all items from the specified slot into active item. Delegates to
inst.components.inventory:TakeActiveItemFromAllOfSlot()if present, otherwise uses classified. - Parameters:
slot-- integer slot index
- Returns: nil
- Error states: None.
AddOneOfActiveItemToSlot(slot)
- Description: Adds one item from active item to the stack in the specified slot. Delegates to
inst.components.inventory:AddOneOfActiveItemToSlot()if present, otherwise uses classified. - Parameters:
slot-- integer slot index
- Returns: nil
- Error states: None.
AddAllOfActiveItemToSlot(slot)
- Description: Adds all of active item to the stack in the specified slot. Delegates to
inst.components.inventory:AddAllOfActiveItemToSlot()if present, otherwise uses classified. - Parameters:
slot-- integer slot index
- Returns: nil
- Error states: None.
SwapActiveItemWithSlot(slot)
- Description: Swaps active item with the item in the specified slot. Delegates to
inst.components.inventory:SwapActiveItemWithSlot()if present, otherwise uses classified. - Parameters:
slot-- integer slot index
- Returns: nil
- Error states: None.
UseItemFromInvTile(item)
- Description: Uses an item from the inventory tile. Delegates to
inst.components.inventory:UseItemFromInvTile()if present, otherwise uses classified. - Parameters:
item-- entity to use
- Returns: nil
- Error states: None.
ControllerUseItemOnItemFromInvTile(item, active_item)
- Description: Uses active item on another item from inventory tile (controller input). Delegates to
inst.components.inventory:ControllerUseItemOnItemFromInvTile()if present, otherwise uses classified. - Parameters:
item-- target item entityactive_item-- active item entity
- Returns: nil
- Error states: None.
ControllerUseItemOnSelfFromInvTile(item)
- Description: Uses item on self from inventory tile (controller input). Delegates to
inst.components.inventory:ControllerUseItemOnSelfFromInvTile()if present, otherwise uses classified. - Parameters:
item-- item entity to use
- Returns: nil
- Error states: None.
ControllerUseItemOnSceneFromInvTile(item)
- Description: Uses item on scene from inventory tile (controller input). Delegates to
inst.components.inventory:ControllerUseItemOnSceneFromInvTile()if present, otherwise uses classified. - Parameters:
item-- item entity to use
- Returns: nil
- Error states: None.
InspectItemFromInvTile(item)
- Description: Inspects an item from inventory tile. Delegates to
inst.components.inventory:InspectItemFromInvTile()if present, otherwise uses classified. - Parameters:
item-- item entity to inspect
- Returns: nil
- Error states: None.
DropItemFromInvTile(item, single)
- Description: Drops an item from inventory tile. Delegates to
inst.components.inventory:DropItemFromInvTile()if present, otherwise uses classified. - Parameters:
item-- item entity to dropsingle-- boolean to drop single item vs whole stack
- Returns: nil
- Error states: None.
CastSpellBookFromInv(item)
- Description: Casts a spell from a spellbook item in inventory. Delegates to
inst.components.inventory:CastSpellBookFromInv()if present, otherwise uses classified. - Parameters:
item-- spellbook item entity
- Returns: nil
- Error states: None.
EquipActiveItem()
- Description: Equips the active item if it is equippable. Delegates to
inst.components.inventory:EquipActiveItem()if present, otherwise uses classified. - Parameters: None.
- Returns: nil
- Error states: None.
EquipActionItem(item)
- Description: Equips an action item. Delegates to
inst.components.inventory:EquipActionItem()if present, otherwise uses classified. - Parameters:
item-- item entity to equip
- Returns: nil
- Error states: None.
SwapEquipWithActiveItem()
- Description: Swaps equipped item with active item. Delegates to
inst.components.inventory:SwapEquipWithActiveItem()if present, otherwise uses classified. - Parameters: None.
- Returns: nil
- Error states: None.
TakeActiveItemFromEquipSlot(eslot)
- Description: Takes active item from the specified equip slot. Delegates to
inst.components.inventory:TakeActiveItemFromEquipSlot()if present, otherwise uses classified. - Parameters:
eslot-- integer equip slot index
- Returns: nil
- Error states: None.
MoveItemFromAllOfSlot(slot, container)
- Description: Moves all items from slot to a container. Delegates to
inst.components.inventory:MoveItemFromAllOfSlot()if present, otherwise uses classified. - Parameters:
slot-- integer slot indexcontainer-- target container entity
- Returns: nil
- Error states: None.
MoveItemFromHalfOfSlot(slot, container)
- Description: Moves half of items from slot to a container. Delegates to
inst.components.inventory:MoveItemFromHalfOfSlot()if present, otherwise uses classified. - Parameters:
slot-- integer slot indexcontainer-- target container entity
- Returns: nil
- Error states: None.
MoveItemFromCountOfSlot(slot, container, count)
- Description: Moves a specific count of items from slot to a container. Delegates to
inst.components.inventory:MoveItemFromCountOfSlot()if present, otherwise uses classified. - Parameters:
slot-- integer slot indexcontainer-- target container entitycount-- number of items to move
- Returns: nil
- Error states: None.
OnVisibleDirty(classified) (local)
- Description: Event callback fired when
visiblenetvar changes. Shows or hides the inventory UI based on the new value. - Parameters:
classified-- the classified entity
- Returns: nil
- Error states: None.
OnHeavyLiftingDirty(classified) (local)
- Description: Event callback fired when
heavyliftingnetvar changes. Updates action filter stack onplayeractionpickerto restrict actions when heavy lifting. - Parameters:
classified-- the classified entity
- Returns: nil
- Error states: None.
OnFloaterHeldDirty(classified) (local)
- Description: Event callback fired when
floaterheldnetvar changes. Updates action filter stack and triggers stategraph events (sg_startfloatingorsg_stopfloating). - Parameters:
classified-- the classified entity
- Returns: nil
- Error states: None.
OpenInventory(inst, self) (local)
- Description: Static task callback that opens the inventory after a delay. Hides inventory if entity is a revivable corpse with
corpsetag. - Parameters:
inst-- the entity instanceself-- the inventory component
- Returns: nil
- Error states: Errors if
inst.components.inventoryis nil (no guard before:Open()call). Errors if accessinginst.components.revivablecorpsewhen component is missing.
Events & listeners
- Listens to (on master):
newactiveitem-- updates classified active item when active item changes. Data:{item = entity}itemget-- updates classified slot when item is added. Data:{slot = number, item = entity, src_pos = vector}itemlose-- clears classified slot when item is removed. Data:{slot = number}equip-- updates classified equip slot. Data:{eslot = number, item = entity}unequip-- clears classified equip slot. Data:{eslot = number}
- Listens to (on client via classified):
visibledirty-- triggersOnVisibleDirtywhen visibility netvar changesheavyliftingdirty-- triggersOnHeavyLiftingDirtywhen heavy lifting netvar changesfloaterhelddirty-- triggersOnFloaterHeldDirtywhen floater held netvar changesonremove(on classified) -- triggers detach callback when classified is removed
- Pushes:
newactiveitem-- fired inDetachClassified()to clear active item. Data:{}inventoryclosed-- fired inDetachClassified()to signal inventory close. Data: none
Note: The netvars visible, heavylifting, and floaterheld belong to the inventory_classified prefab entity, not this component directly. This component reads/writes them via the classified entity reference.