0

I have populated an array through the unity inspector by dragging and dropping the items into it. They show up in inside the array in the inspector, but when I try to reference an object I receive a NullReferenceException as if the array is empty.

Unity inspector with array populated with objects named 1 - 20: http://imgur.com/ezwO1T9

Reference:

    private void PopulateHousesandRooms()
{
    for (int i = 0; i < 20; i++)
    {
        HousesAndRooms[1][1][i] = House1Room1Objects[i];

Error: http://imgur.com/k1cNtDH

Where am I going wrong here? Everything seems fine to me. I hope I'm not wasting your time with a stupid mistake.

Edit: I know what a NullReferenceException is, I'm not asking that. This shouldn't throw a Null Reference should it? There IS an object there. Is the problem with the fact I populated it through the inspector?

Torantula
  • 75
  • 1
  • 9
  • Maybe it starts at index 0? HousesAndRooms[0][0][i] – Thomas Weller Aug 22 '17 at 14:33
  • I also suspect `HousesAndRooms[1][1][i]` not `House1Room1Objects` populated from the Editor. – Programmer Aug 22 '17 at 14:35
  • If you [read the linked article](https://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) you'll also find explainations on how to locate, debug and fix the error by yourself. Without guessing. – Uwe Keim Aug 22 '17 at 14:38
  • I dragged and dropped the objects onto House1Room1Objects in the inspector, see top of image. I am trying to add these items added through the inspector to the array HousesAndRooms FROM House1Room1Objects. – Torantula Aug 22 '17 at 14:39
  • I should also mention this is the only time this array has been referenced in the code, other than: `public GameObject[] House1Room1Objects;` at the start. – Torantula Aug 22 '17 at 14:42
  • Thank you for the link, that is useful, however how would I go about using it in this instance as there is only one place this array is mentioned in the code, so nothing should be uninitializing it. – Torantula Aug 22 '17 at 14:46

0 Answers0