title: Having trouble loading "neighbours" of a specific tile into a List
body: <p>this is my first time asking questions here, i'm actually having a problem in my script:
  I'm trying to add the neighbors of a tile into a list, but i keep getting the NullReferenceException: Object reference not set to an instance of an object when trying to print what's inside the list.</p>
  
  <p>To note that the first "list.Add" is actually working, the others aren't.
  To test it i'm always trying to find something that exists, all Tile_(x)_(y) exists.</p>
  
  <pre><code>using UnityEngine;
  using System.Collections;
  using System.Collections.Generic;
  
  public class TileStats : MonoBehaviour {
  
      public int x;
      public int y;
      public List&lt;GameObject&gt; neighbours;
  
      public List&lt;GameObject&gt; populateNeighbours ()
      {
          List&lt;GameObject&gt; list = new List&lt;GameObject&gt;();
          //If we're at x, y.
          //Left one is at x-1,y
          list.Add(GameObject.Find("Tile_" + (x-1) + "_" + y));
  
          //Right one is at x+1,y
          list.Add(GameObject.Find("Tile_" + (x+1) + "_" + y));
  
  
          //Bottom ones are at x,y-1 and x+1,y-1
          list.Add(GameObject.Find("Tile_" + x + "_" + (y-1)));
          list.Add(GameObject.Find("Tile_" + (x+1) + "_" + (y-1)));
  
          //Top ones are at x,y+1 and x+1,y+1
          list.Add(GameObject.Find("Tile_" + x + "_" + (y+1)));
          list.Add(GameObject.Find("Tile_" + (x+1) + "_" + (y+1)));
          return list;
  
      }
  }
  
  
  ...
  Tile_GO.GetComponent&lt;TileStats&gt;().x = x;
  Tile_GO.GetComponent&lt;TileStats&gt;().y = y;
  Tile_GO.GetComponent&lt;TileStats&gt;().neighbours=Tile_GO.GetComponent&lt;TileStats&gt;().populateNeighbours();
  ...
  </code></pre>
  
  <p>The error is thrown when i try to print the input:
      foreach (GameObject obj in ourHitObject.GetComponent().neighbours) {
                      print("Name: " + obj.name + "Atual: " + i++);
                  }</p>
  
  <p>SOLVED</p>
  
  <blockquote>
    <p>@AnthonyLeal I looked at the code and that is the problem. You are searching for GameObject while do they don't exist. Just think about it like this: Your generated a gameObject in your for loop then called the populateNeighbours() function in that for loop. That populateNeighbours() function does not operate on the generated GameObject in that loop. It looks for other GameObjects that are not yet generated. You did this many many times leading to over 500 errors. – Programmer </p>
  </blockquote>