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 InventorySlot

Remarks

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

Goal
How

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.

Parameter
Type
Description

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.

Parameter
Type
Description

itemID

ItemID

The item to store

itemAmount

int

Quantity (default: 1)

SetAmount

Updates only the quantity without changing the item ID.

Parameter
Type
Description

itemAmount

int

New quantity

Clear

Resets the slot to empty — sets itemID to ItemID.Invalid and itemAmount to 0.

Common Pitfalls

circle-exclamation
circle-exclamation

See Also

  • Inventory — the container that owns and manages slots

  • Item — the item type whose ID is stored in slots

Last updated