- Home /
inventory system item buttons flag error NullReferenceException: Object reference not set to an instance of an object
created an inventory system and while each item worked the button that uses the item would always be the same regardless of what item it was. to fix this I used this
public void ListItems()
{
foreach (var InventoryItem in inventoryItems)
{
GameObject obj = Instantiate(inventoryItemObject, itemContent);
var item_name = obj.transform.Find("inventory/Item_name").GetComponent<Text>();
var item_icon = obj.transform.Find("inventory/Item_icon").GetComponent<Image>();
item_name.text = InventoryItem.item_name;
item_icon.sprite = InventoryItem.item_icon;
}
}
the issue is it doesn't work and I get the error: NullReferenceException: Object reference not set to an instance of an object InventoryManager.ListItems () (at Assets/Scripts/InventoryManager.cs:47)
the names Item_name and Item_icon do match with those varibles each item has and the items are in the inventory folder
so I don't know how this isn't working
Your answer

Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Decorator pattern for inventory item class 0 Answers
[Solved]Instantiated item won't get destroyed until "picked up" again. 1 Answer
unity3d simple inventory 1 Answer