title: Unity: Cannot modify / add values to an array in System.Serializable
body: <p>I have a System.Serializable class</p>
  <pre><code>[System.Serializable]
  public class _answersData
  {
      public string word;
      public string wordmeaning;
      public string wordmeaning2;
      public GameObject result;    
  }
  </code></pre>
  <p>I then have a monobehaviour class where an array of _answerData class is declared</p>
  <pre><code>public class gamePlay : MonoBehaviour
  {
      public _answersData[] answersData;
  }
  </code></pre>
  <p>I am then trying to add data to _answerData array from another script using below method</p>
  <pre><code>public class challengeScript: MonoBehaviour
  {
      void Start()
      {
          gameplayScript = gameObject.GetComponent&lt;gamePlay&gt;();
          populate();
      }
      
      void populate()
      {
          answersCount = int.Parse(snapshot.Child(&quot;Answers&quot;).Child(&quot;Count&quot;).Value.ToString());
          gameplayScript.answersData = new _answersData[answersCount];
  
          for (int i = 0; i &lt; answersCount; i++)
          {
              string positionNode = &quot;Answer&quot; + (i + 1).ToString();
              string _word = snapshot.Child(&quot;Answers&quot;).Child(positionNode).Child(&quot;Word&quot;).Value.ToString();
              gameplayScript.answersData[i].word = _word;   
          }
      }
  }
  </code></pre>
  <p>but I am getting NullReferenceException at 'gameplayScript.answersData[i].word = _word' line</p>
  <p>Here's the error:</p>
  <blockquote>
  <p>NullReferenceException: Object reference not set to an instance of an object</p>
  </blockquote>
  <p>Can someone guide what I am doing wrong here?</p>