The Ultimate Grid Inventory (UGI) system provides a powerful Scriptable Object called InventorySupplierSo that makes it easy to programmatically interact with inventory grids and holders. This guide explains how to use this tool to manage items in your game code.
Here's a complete example of how to add an item to a player's inventory:
using Inventory.Scripts.Core.Enums;using Inventory.Scripts.Core.ScriptableObjects;using Inventory.Scripts.Core.ScriptableObjects.Items;using UnityEngine;public class AddItemToGrid : MonoBehaviour{ [SerializeField] private InventorySo playerInventory; [SerializeField] private InventorySupplierSo inventorySupplierSo; [SerializeField] private ItemDataSo itemWhichWillBeInserted; public void InsertItemOnPlayerInventory() { // Try to find a place for the item in any of the player's inventory grids var (item, gridResponse) = inventorySupplierSo.FindPlaceForItemInGrids( itemWhichWillBeInserted, // The item we want to add playerInventory.GetGrids() // All available grids in the player's inventory ); if (gridResponse == GridResponse.Inserted) { Debug.Log("Item was successfully added to inventory!"); // You can trigger additional effects or UI updates here } else { Debug.Log("Could not add item - inventory might be full"); // Handle the failed insertion (show message, drop item in world, etc.) } }}