title: Missing reference exception in Unity after instantiating multiple GameObject prefabs and deleting original
body: <p>I am currently making a Breakout style game and have 2 "Power-ups" that are giving me some trouble. I have a double-ball and triple-ball power-ups that instantiate 1 or 2 extra balls from an original ball prefab.</p>
  
  <p>Everything works fine as long as the original ball is still in the scene but after the original ball from the scene is deleted (The ball is destroyed after it hits the bottom of the screen but the game continues if the cloned balls are still in play and the "Ball Count" is not 0) I get the following error in the lines containing the Instantiate function in the double and triple power-up cases:</p>
  
  <blockquote>
    <p>MissingReferenceException: The object of type 'Transform' has been destroyed but you are still trying to access it.</p>
  </blockquote>
  
  <p>The portion of my Paddle Code handles the powers on collision between the paddle and the powerup is as follows:</p>
  
  <pre><code>void OnTriggerEnter2D(Collider2D collision)
  {
      GameObject[] ArrayOfBalls = GameObject.FindGameObjectsWithTag("Ball");
  
      switch (collision.tag)
      {
          case "Life Powerup" :
              Debug.Log("hit " + collision.name);
              gm.UpdateLives(1);
              Destroy(collision.gameObject);
              break;
  
          case "Speed PowerUp":
  
              for (int i = 0; i&lt;ArrayOfBalls.Length; i++)
              {
                  ball ballscript = ArrayOfBalls[i].GetComponent &lt; ball&gt;();
                  if (ballscript.rb.velocity.magnitude &gt; 7.5f)
                  {
                      CancelInvoke("NormalSpeed");
                      Invoke("NormalSpeed", 5f);
  
                  }
                  else if (ballscript.rb.velocity.magnitude &lt;= 7.5f)
                  {
                      ballscript.rb.velocity = new Vector2(ballscript.rb.velocity.x * 1.5f, ballscript.rb.velocity.y * 1.5f);
                      Invoke("NormalSpeed", 5f);
                  }
  
              }
  
              //If another powerup is collected call to function to slow down is cancelled and started with new delay
  
  
              Debug.Log("hit " + collision.name);
              Destroy(collision.gameObject);
              break;
  
          case "Shrink PowerDown":
  
              gameObject.transform.localScale = new Vector3( 0.25f, 0.4f, 1f);
              Invoke("NormalSize", 15);
  
              Debug.Log("hit " + collision.name);
              Destroy(collision.gameObject);
              break;
  
          case "Expand PowerUp":
  
              gameObject.transform.localScale = new Vector3( 0.55f, 0.4f, 1f);
              Invoke("NormalSize", 5f);
              Debug.Log("hit " + collision.name);
              Destroy(collision.gameObject);
              break;
  
          case "Double PowerUp":
              for (int i = 0; i &lt; ArrayOfBalls.Length; i++)
              {
                  ball ballscript = ArrayOfBalls[i].GetComponent&lt;ball&gt;();
                  Transform Doubleclone = Instantiate(PrefabBall, new Vector3(ballscript.rb.position.x + 0.1f, ballscript.rb.position.y + 0.1f, 0f), Quaternion.identity);
                  Doubleclone.GetComponent&lt;Rigidbody2D&gt;().velocity = new Vector2(ballscript.rb.velocity.x, ballscript.rb.velocity.y);
                  gm.UpdateBallCount(1);
  
  
              }
              Debug.Log("hit " + collision.name);
              Destroy(collision.gameObject);
              break;
  
          case "Triple PowerUp":
              for (int i = 0; i &lt; ArrayOfBalls.Length; i++)
              {
  
                  ball ballscript = ArrayOfBalls[i].GetComponent&lt;ball&gt;();
                  Transform Tripleclone = Instantiate(PrefabBall, new Vector3(ballscript.rb.position.x + 0.1f, ballscript.rb.position.y + 0.1f, 0f), Quaternion.identity);
                  Transform Tripleclone2 = Instantiate(PrefabBall, new Vector3(ballscript.rb.position.x - 0.1f, ballscript.rb.position.y - 0.1f, 0f), Quaternion.identity);
                  Tripleclone.GetComponent&lt;Rigidbody2D&gt;().velocity = new Vector2(ballscript.rb.velocity.x, ballscript.rb.velocity.y);
                  Tripleclone2.GetComponent&lt;Rigidbody2D&gt;().velocity = new Vector2(ballscript.rb.velocity.x, ballscript.rb.velocity.y);
                  gm.UpdateBallCount(2);
  
              }
  
              Debug.Log("hit " + collision.name);
              Destroy(collision.gameObject);
              break;
  
      }
  </code></pre>
  
  <p>I don't know what a good fix for this would be and appreciate any ideas!</p>