Im following the Adventure game tutorial to build an Inventory, in the tutorial they are only using 4 item slots, I need a few more than that. But when I try to add even one more slot I get the following errors when i try to click on the editor down arrow (on the far right) "for item slot 4":
All I have done is change the number of slots from 4 to 5:
public class Inventory : MonoBehaviour
public Image itemImages = new Image[numItemSlots];
public Item items = new Item[numItemSlots];
public const int numItemSlots = 5;
public void AddItem(Item itemToAdd)
int id = itemToAdd.id;
if (items.Length <= id)
if (items [id]== null)
items[id] = itemToAdd;
itemImages[id].sprite = itemToAdd.sprite;
itemImages[id].enabled = true;
public void RemoveItem(Item itemToRemove)
for (int i = 0; i < items.Length; i++)
if (items[i] == itemToRemove)
items[i] = null;
itemImages[i].sprite = null;
itemImages[i].enabled = false;
Answer by mellovely
3 days ago
In case anyone comes here with the same problem.
Adding these two lines in my Inventory Editor code worked for me and allowed me to add 26 numItemSlots! :)
public override void OnInspectorGUI()
itemImagesProperty.arraySize = Inventory.numItemSlots;
itemsProperty.arraySize = Inventory.numItemSlots;
for (int i= 0; i < Inventory.numItemSlots; i++)
Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.
The best place to ask and answer questions about development with Unity.
To help users navigate the site we have posted a site navigation guide.
If you are a new user to Unity Answers, check out our FAQ for more information.
Make sure to check out our Knowledge Base for commonly asked Unity questions.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, see the list of changes.
Answers and Comments
3 People are following this question.
Instantiating object from inventory
Inventory SlotID vs. RectPosition
"NullReferenceException" while trying to draw a texture (C#)
Click on a button that is created post start.
Error: you are pushing more GUIClips than you are poping.