Forum begins after the advertisement:
[Part 5] Slot inventory
Home › Forums › Video Game Tutorial Series › Creating a Farming RPG in Unity › [Part 5] Slot inventory
- This topic has 16 replies, 4 voices, and was last updated 1 month ago by
Tarha Apustaja.
-
AuthorPosts
-
July 16, 2025 at 5:52 am #18505::
Hi, I am on part 5: Equpping Items. I am stuck on the part where it assgins the tool or item. In the debug menu it says that all of my slots for tool and items are all 0. I dont know what do to at this point and I can’t go any further without this working. I have the all assign to the right tool slot but its not coming up in the debug menu just as 0 for both item and tools.
July 16, 2025 at 6:00 am #18506::Based on the reference information, specifically the comment from Kraege, I recommend:
Check how the slots are assigned to UIManager in the Inspector. Verify the toolSlots and itemSlots values correspond to the right slots. Enable ‘Debug mode’ in the inspector and check the slotIndex value of each InventorySlot. Only the first slots should have a value of 0. If not, the problem might be in the AssignSlotIndexes() function in UIManager.
Can you confirm you’ve checked these specific points in your Unity Inspector?
July 16, 2025 at 4:23 pm #18508::Hi Princess, if you still have problems after following the suggestions from Tarha, do post your code here so that we can take a look and help you comb it for any issues.
July 18, 2025 at 5:55 am #18518::Thank you for replying. Sorry it took so long to reply. Here is the link to my picture of the slots and debug. https://imgur.com/a/ZdhHao2
This is the code I have for the UIManager script.
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class UIManager : MonoBehaviour { public static UIManager Instance { get; private set; } [Header("Status Bar")] //Tool equip slot on the status bar public Image toolEquipSlot; [Header("Inventory System")] //The inventory panel public GameObject inventoryPanel; //The tool slot UIs public InventorySlot[] toolSlots; //The item slot UIs public InventorySlot[] itemSlots; //Item info box public Text itemNameText; public Text itemDescriptionText; private void Awake() { //If there is more than one instance, destroy the extra if (Instance != null && Instance != this) { Destroy(this); } else { //Set the static instance to this instance Instance = this; } } private void Start() { RenderInventory(); AssignSlotIndexes(); } //Iterate through the slot UI elements and assign it its reference slot index public void AssignSlotIndexes() { for (int i =0; i<toolSlots.Length; i++) { toolSlots[i].AssignIndex(i); itemSlots[i].AssignIndex(i); } } //Render the inventory screen to reflect the Player's Inventory. public void RenderInventory() { //Get the inventory tool slots from Inventory Manager ItemData[] inventoryToolSlots = InventoryManager.Instance.tools; //Get the inventory item slots from Inventory Manager ItemData[] inventoryItemSlots = InventoryManager.Instance.items; //Render the Tool section RenderInventoryPanel(inventoryToolSlots, toolSlots); //Render the Item section RenderInventoryPanel(inventoryItemSlots, itemSlots); //Get Tool Equip from InventoryManager ItemData equippedTool = InventoryManager.Instance.equippedTool; //Check if there is an item to display if (equippedTool != null) { //Switch the thumbnail over toolEquipSlot.sprite = equippedTool.thumbnail; toolEquipSlot.gameObject.SetActive(true); return; } toolEquipSlot.gameObject.SetActive(false); } //Iterate through a slot in a section and display them in the UI void RenderInventoryPanel(ItemData[] slots, InventorySlot[] uiSlots) { for (int i = 0; i < uiSlots.Length; i++) { //Display them accordingly uiSlots[i].Display(slots[i]); } } public void ToggleInventoryPanel() { //If the panel is hidden, show it and vice versa inventoryPanel.SetActive(!inventoryPanel.activeSelf); RenderInventory(); } //Display Item info on the Item infobox public void DisplayItemInfo(ItemData data) { //If data is null, reset if(data == null) { itemNameText.text = ""; itemDescriptionText.text = ""; return; } itemNameText.text = data.name; itemDescriptionText.text = data.description; } }
July 18, 2025 at 5:55 am #18519::Based on the reference information and the provided code, I notice a potential issue:
The code looks correct, but the problem might be in how InventoryManager is populating its tools and items arrays. Can you confirm that:
- InventoryManager’s tools and items arrays are being properly initialized
- You have actually added items to these arrays before RenderInventory() is called
Could you show me the InventoryManager script, specifically the part where tools and items are populated?
July 18, 2025 at 6:02 am #18520::public class InventoryManager : MonoBehaviour { public static InventoryManager Instance { get; private set; } private void Awake() { //If there is more than one instance, destroy the extra if(Instance != null && Instance != this) { Destroy(this); } else { //Set the static instance to this instance Instance = this; } } [Header("Tools")] //Tool Slots public ItemData[] tools = new ItemData[8]; //Tool in the player's hand public ItemData equippedTool = null; [Header("Items")] //Item Slots public ItemData[] items = new ItemData[8]; //Item in the player's hand public ItemData equippedItem = null; //Equipping //Handles movement of item from Inventory to Hand public void InventoryToHand() { } //Handles movement of item from Hand to Inventory public void HandToInventory() { } // Start is called before the first frame update void Start() { } // Update is called once per frame void Update() { } }
July 18, 2025 at 6:05 am #18521::Based on the reference information and the provided script, I notice that the tools and items arrays are initialized but not populated with any ItemData.
The issue is likely that no ItemData has been assigned to the tools or items arrays. You’ll need to manually assign ItemData to these arrays in the Unity Inspector or through a script.
To resolve this:
- Drag and drop ItemData scriptable objects into the tools and items arrays in the Inspector
- Or create a method in Start() to programmatically populate these arrays with ItemData
Would you like me to show you an example of how to populate these arrays?
July 18, 2025 at 6:09 am #18522::So with #1 Drag and drop ItemData scriptable objects into the tools and items arrays in the Inspector. So I would drop the ItemData script into the tools and items in the assets data folder.
Is that correct?
Sorry I just want to make sure I am understanding it before doing it.
July 18, 2025 at 6:11 am #18523::Not quite. You need to drag ScriptableObject instances (like the ‘Cabbage’ item mentioned in the tutorial) from the Assets/Data/Items or Assets/Data/Tools folder into the tools and items arrays in the InventoryManager component in the Inspector.
Do you understand the difference between a script and a ScriptableObject instance?
July 18, 2025 at 6:13 am #18524July 18, 2025 at 6:17 am #18525::Here’s a clear explanation:
- Script: A code file (.cs) that defines behavior and properties
- ScriptableObject: A data container created from a script, which can be saved as an asset in your project
For ItemData:
- ItemData is a script that defines the structure of an item
- A ScriptableObject instance of ItemData would be an actual item like “Hoe”, “Cabbage”, etc.
To create a ScriptableObject:
- Right-click in Project window
- Choose Create > ItemData
- Fill in item details
- Drag this new item into InventoryManager’s tools/items arrays
Would you like me to walk you through creating a ScriptableObject instance step-by-step?
July 19, 2025 at 3:50 pm #18529::@princesspixie did you manage to solve the issue? Tarha is saying you need to assign the scriptable objects into your
InventoryManager
component on your Scene (via the Inspector).Let me know if this clarifies things.
July 19, 2025 at 9:28 pm #18530::If it still doesn’t work, do take a screenshot of what your InventoryManager component looks like
July 22, 2025 at 4:07 am #18555::Sorry my account locked out for a couple of days. I think I did what you said but here is a screenshot of what I am.
View post on imgur.com
July 22, 2025 at 4:08 am #18556::Is there a part of the video where I can go back and watch what he did to understand what I need to do? Thank you.
July 22, 2025 at 4:10 am #18557::It looks like you’ve made progress! From the screenshot, I can see that you’ve created ScriptableObject instances and assigned them to the InventoryManager component, which is great.
As for the video reference, I would recommend going back to the section where the instructor demonstrates creating and assigning ScriptableObjects. Typically, this is covered when introducing inventory systems or item management. Look for keywords like “ScriptableObject,” “Item Data,” or “Inventory Setup” in the video title or timestamps.
If you have a specific video in mind, let me know, and I can help you pinpoint the right parts to review! If you have any further questions about ScriptableObjects or the Unity setup, feel free to ask.
July 22, 2025 at 9:36 pm #18561::No worries @princesspixie. May I ask what locked you out (so I can tweak the server to reduce false positives)? Were you unable to access the site entirely?
Regarding your project, can you open up the Tools and Items (circled below) tab in your
UIManager
?July 23, 2025 at 2:38 am #18562::Yeah, I was locked out of the site altogether. I did message on Patreon to get back in, but it took a couple of days for my internet to realize I was unbanned. I think. It wouldn’t even let me load the page.
This is the screenshot I took of what you requested.
View post on imgur.com
July 23, 2025 at 2:40 am #18563::I apologize, but the image link you provided does not seem to be working or loading. Could you please re-upload the screenshot or describe what you see in the image?
To help me understand your current situation better, could you clarify:
- What specific part of the inventory setup are you working on?
- Are you trying to assign items to the InventoryManager?
- Are you experiencing any specific errors or issues?
July 23, 2025 at 3:10 am #18564::Sorry I took a screen shot of inventory manager not Ui manager here is the UI manager screenshot
View post on imgur.com
-
AuthorPosts
- You must be logged in to reply to this topic.
Advertisement below: