Shop Max Quantity
💡
3
As the title says
- Start by going into your
ItemScript and Add this under your existing fields (e.g. after m_price):
[Header("Shop Settings")]
[SerializeField, Min(0)] private int m_maxShopQuantity = 0; // 0 = unlimited
public int maxShopQuantity => m_maxShopQuantity;
- after this, make sure that you have this line of code in your
InventorySystemscript, if not, add this:
public int GetItemCount(Item item)
{
if (items.TryGetValue(item, out int count))
{
return count;
}
return 0;
}
- Now go into your
UIShopscript and replace theOnShopSlotClicked(Item item)with this:
private async void OnShopSlotClicked(Item item)
{
// 1) Max quantity check
int maxQty = item.maxShopQuantity; // 0 = unlimited
if (maxQty > 0)
{
int owned = GameManager.InventorySystem.GetItemCount(item);
if (owned >= maxQty)
{
// Player already owns the max allowed amount
// Reuse your "cannot buy" dialogue
await GameManager.DialogueSystem.Main.PlayNow(
DialogueUtils.CreateDialogueTree(
m_cannotBuy,
null,
item.displayName
)
);
return;
}
}
// 2) Normal price & money check
int itemPrice = m_shop.GetPrice(item, ETransactionType.Buy);
if (GameManager.InventorySystem.money >= itemPrice)
{
GameManager.InventorySystem.RemoveMoney(itemPrice);
GameManager.InventorySystem.AddToBag(item, 1, EItemTransferType.Trading);
GameManager.NotificationSystem.audioPlaybackRequested.Invoke(m_buySellAudio);
// For better UX: jump to category of purchased item
m_inventoryBag.SetCategory(item.category);
// 3) Refresh inventory & shop (skip rebuilding bag item slots)
UpdateUI(true);
}
else
{
await GameManager.DialogueSystem.Main.PlayNow(
DialogueUtils.CreateDialogueTree(
m_cannotBuy,
null,
item.displayName
)
);
}
}
- Still in
UIShop, replace yourFillSlots()with this:
private void FillSlots()
{
int itemCount = m_shop.items.Length;
m_slots = new UIShopEntry[itemCount];
int slotIndex = 0;
for (int i = 0; i < itemCount; ++i)
{
Item item = m_shop.items[i];
// --- NEW: skip sold-out items ---
int maxQty = item.maxShopQuantity;
if (maxQty > 0)
{
int owned = GameManager.InventorySystem.GetItemCount(item);
if (owned >= maxQty)
{
continue; // don't create a slot for this item
}
}
// --------------------------------
GameObject itemSlot = Instantiate(m_shopEntryPrefab, m_itemSlotsRoot.transform);
UIShopEntry shopEntry = itemSlot.GetComponent<UIShopEntry>();
if (shopEntry)
{
shopEntry.Initialize(item);
m_slots[slotIndex] = shopEntry;
++slotIndex;
}
}
}
and you should be good to go! now just set a max quantity on your items prefab!
If there’s any issues let me know!

💬 Comments (0)
Be the first to comment! Join our Discord to share your thoughts.
Want to continue the conversation?