MissingReferenceException Instantiate

Hi Unity Community, i try to make an arkanoid-like game, every 2000 score point, the game make a clone of a ball, with this piece of code:

function Update () {
	score3DText.text = "Score: " + score.ToString();
	if (activeBall > 2000){
		clone = Instantiate(ballclone, transform.position, transform.rotation);
		activeBall = 0;
		countBall +=1;
	}

however, when the “mother ball” fall out the camera screen (and the game delete it), the general script can’t instantiate another cloneball because it have a missing reference exception.

how can i solve the problem?

sorry for my bad English…

It sounds like you need to make the ball as a prefab and then reference the prefab as the first argument when instantiating.

i do it, but the problem persist. :frowning:

This is because you’re destorying the prefab gameObject, thus it cannot be referenced any longer to create a new instantiation of it.

You want to destroy the Instantiated prefab, not the prefab.

ok, so, what i must instantiate?

thanks for help :slight_smile:

You must instantiate the prefab and destroy the result of the instantiate. The Instantiate method returns a reference to the newly created ball. It is that one that you must destroy.

If you already have a ball in the scene that was not instantiated using code you can destroy it by calling DestroyObject( this.gameObject )