Hello, I am making a crafting system and want to add all of the items names that are in the grid to be added to a list so I can check what items are in there, however when iterating through each grid using a foreach
loop it gives a reference error.
private void CheckItemsInOven()
{
itemsInOven.Clear();
foreach (InventorySlot ovenSlot in ovenSlots)
{
if (ovenSlot.GetComponentInChildren<InventoryItem>() != null)
{
string item = ovenSlot.GetComponentInChildren<InventoryItem>().item.itemName;
itemsInOven.Add(item);
if(CheckRecipe(itemsInOven))
{
CookRecipe(true);
}
else
{
CookRecipe(false);
}
}
}
}
this error only started occurring after I added .item.itemName
, if I were to remove that and change list to type InventoryItem
it works fine. any help would be appreciated.