title: NullReferenceException: Object reference not set to an instance of an object error when accessing method from script attached to game object
body: <p>I keep getting the error <code>NullReferenceException: Object reference not set to an instance of an object</code> when trying to access a method from an attached script.</p>
  
  <p>My editor code below creates prefab copies in a circle. I placed a prefab for the <code>clonedObject</code></p>
  
  <p>CircleSpawn</p>
  
  <pre><code>    public class CircleSpawn : MonoBehaviour
  {
  
      public float radius, radiusLast, spin, spinLast;
      public int numOfItems;
      //public int oldNumOfItems = 0;
      public GameObject clonedObject;
      public List&lt;GameObject&gt; spawnedObjects;
  
  
  }
  </code></pre>
  
  <p>CircleSpawnEditor</p>
  
  <pre><code>    [CustomEditor(typeof(CircleSpawn))]
  public class CircleSpawnEditor : Editor
  {
  
      public override void OnInspectorGUI()
      {
          var tar = (CircleSpawn)target;
          tar.clonedObject = (GameObject)EditorGUILayout.ObjectField(tar.clonedObject,
              typeof(GameObject), true);
          if (!tar.clonedObject) return;
  
  
          EditorGUILayout.LabelField("Radius"); // Set as required
          tar.radius = EditorGUILayout.Slider(tar.radius, 0f, 5f);
          EditorGUILayout.LabelField("Angle"); // Set as required
          tar.spin = EditorGUILayout.Slider(tar.spin, 0f, 360f);
          EditorGUILayout.LabelField("Number of Items"); // Set as required
          tar.numOfItems = EditorGUILayout.IntSlider(tar.numOfItems, 0, 12);
          EditorGUILayout.LabelField("Object");
  
          float angle, angleBetween = 360.0f / tar.numOfItems;
  
          if (tar.spawnedObjects == null)
              tar.spawnedObjects = new List&lt;GameObject&gt;();
  
  
          if (tar.spawnedObjects.Count != tar.numOfItems)
          {
              foreach (var ob in tar.spawnedObjects)
                  DestroyImmediate(ob);
  
              tar.spawnedObjects.Clear();
              angle = 0f;
  
              for (int i = 0; i &lt; tar.numOfItems; i++)
              {
                  var rot = Quaternion.Euler(0f, 0f, tar.spin + angle);
                  var localPos = rot * Vector3.right * tar.radius;
                  tar.spawnedObjects.Add(Instantiate(tar.clonedObject,
                  tar.transform.position + localPos, rot));
                  angle += angleBetween;
                  tar.spawnedObjects[i].name = tar.spawnedObjects[i].name + (i + 1);
  
                  var obj = GameObject.Find(tar.spawnedObjects[i].name);
                  var pCreator = obj.GetComponent&lt;PathCreator&gt;();
                  pCreator.DrawBezierCurve();
                  GameObject.Find(tar.spawnedObjects[i].name).GetComponent&lt;PCreator&gt;().Show();
  
  
              }
          }
  
  
          if (!Mathf.Approximately(tar.spin, tar.spinLast) ||
              !Mathf.Approximately(tar.radius, tar.radiusLast))
          {
              tar.spinLast = tar.spin;
              tar.radiusLast = tar.radius;
              angle = 0f;
  
              for (int i = 0; i &lt; tar.numOfItems; i++)
              {
                  var rot = Quaternion.Euler(0f, 0f, tar.spin + angle);
                  var localPos = rot * Vector3.right * tar.radius;
                  tar.spawnedObjects[i].transform.position =
                  tar.transform.position + localPos;
                  tar.spawnedObjects[i].transform.rotation = rot;
                  angle += angleBetween;
  
              }
          }
      }
  }
  </code></pre>
  
  <p>The error occurs at the line </p>
  
  <p><code>GameObject.Find(tar.spawnedObjects[i].name).GetComponent&lt;PCreator&gt;().Show();</code></p>
  
  <p>How can I solve this issue?</p>