Backpack
Based on game build 714014 | Last updated: 2026-03-04
Overview
The backpack prefab implements a wearable inventory container with support for skin-specific visual follow effects (e.g., animation-synced FX attached to the owner during equipping). It integrates closely with the equippable, container, burnable, and inventoryitem components. It serves as a core wearable item in the game's crafting and inventory systems, opening its container UI when equipped and managing its visual representation (including skin overrides and follow FX) on equip/unequip.
Usage example
local backpack = SpawnPrefab("backpack")
backpack.Transform:SetPosition(inst.Transform:GetWorldPosition())
inst.components.inventory:AddItem(backpack, true)
-- When equipped, the backpack's container opens and skin follow FX attach to the owner
Dependencies & tags
Components used: inspectable, inventoryitem, equippable, container, burnable, propagator, highlightchild, colouradder, bloomer, follower
Tags: Adds backpack and FX (for backpack_swap_fx sub-prefab); no tag removal or checking logic in core code.
Properties
No public properties are initialized directly on the backpack entity instance beyond component internal states. Skin-related behavior is exposed via callbacks in inst.backpack_skin_fns (modder-extendable).
Main functions
The backpack prefab is primarily a data-driven entity defined via its fn() constructor. Custom behavior is exposed through callback hooks and event listeners. Key internal functions:
onequip(inst, owner)
- Description: Invoked when the backpack is equipped. Sets up skin overrides, attaches follow FX, and opens the container to the owner.
- Parameters:
inst(entity) – The backpack entity.
owner(entity) – The entity equipping the backpack. - Returns: Nothing.
onunequip(inst, owner)
- Description: Invoked when the backpack is unequipped. Detaches follow FX, reattaches idle FX, clears animation overrides, and closes the container.
- Parameters:
inst(entity) – The backpack entity.
owner(entity) – The entity unequipping the backpack. - Returns: Nothing.
onburnt(inst)
- Description: Called when the backpack is fully burnt. Drops all container contents, closes the container, spawns an
ashprefab, and removes the backpack. - Parameters:
inst(entity) – The backpack entity. - Returns: Nothing.
onignite(inst)
- Description: Called when the backpack is ignited. Disables container opening by setting
canbeopened = false. - Parameters:
inst(entity) – The backpack entity. - Returns: Nothing.
onextinguish(inst)
- Description: Called when the backpack is extinguished. Re-enables container opening by setting
canbeopened = true. - Parameters:
inst(entity) – The backpack entity. - Returns: Nothing.
OnBackpackSkinChanged(inst, skin_build)
- Description: Handler called when the backpack’s skin changes. Resets and reinitializes all follow FX (idle and equip). Removes old FX and recreates them with the new skin build.
- Parameters:
inst(entity) – The backpack entity.
skin_build(string or nil) – The new skin build name. - Returns: Nothing.
ForEachSkinFollowFx(inst, cb, ...)
- Description: Utility to iterate over all active skin follow FX (idle and equipped). Useful for applying changes en masse (e.g., colour/bloom updates).
- Parameters:
inst(entity) – The backpack entity.
cb(function) – Callback invoked with signaturecb(inst, fx, ...).
...(any) – Additional arguments passed tocb. - Returns: Nothing.
OnSave(inst, data) and OnLoad(inst, data, ents)
- Description: Serialization hooks delegated to
inst.backpack_skin_fns.onsaveandinst.backpack_skin_fns.onloadif present. Allows modded skins to persist/restore state. - Parameters:
inst(entity) – The backpack entity.
data(table) – Serialization table.
ents(table, only inOnLoad) – Entity mapping. - Returns: Nothing.
Events & listeners
- Listens to:
equipskinneditem(pushed viaowner:PushEvent(...))
unequipskinneditem(pushed viaowner:PushEvent(...))
onremove– used internally viaListenForEventinBloomer.AttachChild/DetachChildto clean up colour/bloom attachments. - Pushes:
equipskinneditemwithinst:GetSkinName()when equipped with a skin.
unequipskinneditemwithinst:GetSkinName()when unequipped with a skin.
onclose– fired viaContainer.Close(...). - Component-internal listeners:
colouradderandbloomercomponents listen foronremoveon FX entities to detach cleanly.