InventorySlot
Lightweight data container for a single inventory slot. Tracks an ItemID and quantity. Created and owned by an Inventory instance.
Definition
Namespace: Paragon.Townskeep.InventorySystem
Assembly: Townskeep.dll
public class InventorySlotRemarks
InventorySlot is a plain C# class (no Unity base class) that stores the minimal data for one inventory position: an ItemID and an int amount. It does not hold a direct reference to an Item instance — only the ID-based reference via ItemID.
Slots are created by Inventory.Initialize() and should not be constructed externally. Each slot has a back-reference to its owning Inventory and its index position within the inventory array.
Empty slot sentinel
An empty slot is represented by ItemID.Invalid (which is (-1, -1)). The HasItem property checks against this sentinel value.
Quick Lookup
Check if slot has an item
slot.HasItem
Get the item ID
slot.ItemID
Get the item quantity
slot.ItemAmount
Get the slot index
slot.Index
Set an item
slot.SetItem(itemID, amount)
Change quantity only
slot.SetAmount(amount)
Clear the slot
slot.Clear()
Properties
Index
The zero-based position of this slot within its owning inventory.
ItemID
The identifier of the item stored in this slot, or ItemID.Invalid if empty.
ItemAmount
The quantity of the item in this slot (0 if empty).
HasItem
Returns true if the slot contains an item (i.e., ItemID != ItemID.Invalid).
Constructor
InventorySlot(Inventory, int)
Creates a new empty slot with a back-reference to its owning inventory and index position.
inventory
Inventory
The owning inventory
index
int
Zero-based position in the inventory
Initializes itemID to ItemID.Invalid and itemAmount to 0.
Methods
SetItem
Sets the item ID and amount for this slot.
itemID
ItemID
The item to store
itemAmount
int
Quantity (default: 1)
SetAmount
Updates only the quantity without changing the item ID.
itemAmount
int
New quantity
Clear
Resets the slot to empty — sets itemID to ItemID.Invalid and itemAmount to 0.
Common Pitfalls
Direct modifications bypass Inventory events
Calling SetItem(), SetAmount(), or Clear() directly on a slot does NOT fire Inventory.OnInventoryChanged. Always use Inventory.SetSlot() / Inventory.ClearSlot() when event notification is needed.
SetAmount does not validate item presence
SetAmount() can be called on an empty slot (where ItemID is Invalid), setting a quantity for a non-existent item. No validation is performed.
See Also
Last updated