I'm trying to write an inventory system for an RPG. I have custom type called 'Item', and a class called 'Bag'. An item can be put into a bag with this function:
public Item aw = new Item();
public void PutIn(Item aw)
{
Contents[Index]=aw;
Index++;
}
When I call the function with
Bag.PutIn(someItem);
in the main code it throws a System.NullReferenceException. By researching the issue I found out that this is usually caused by improperly initialised objects, but in this case I did initialise the object with Item aw = new Item();. What am I doing wrong?