Destroying a game object

Just have a quick question, if i were to create a public game object in a c# script and assign the object to the script in the editor, what would happen if i end up instantiating that game object into the scene and then later on call destroy on that object, would it delete the reference to that game object i attached or would it actually delete just the instance of the object in the scene?

Example:

public GameObject myObject;

void InstantiateGameObject()
{
	Instantiate(myObject, new Vector3(0, 0, 0), Quaternion.identity);
}
void destroyMyObject()
{
	GameObject go = GameObject.Find(myObject);
	if (myObject != null)
	{
		Destroy(go);
	}
}

Well, look at it as you said it… “If I ‘instantiated’ the object” means… “If I ‘made a copy’ of the object”, “then destroyed that copy, would it destroy the original”

Of course the answer is no.

Thanks, just wanted some reassurance before i finished this class and then had to go back later tonight and redesign it lol. Didnt want to destroy the reference to the gameobject/prefab just want to delete the one that i instantiate =)

I think you might have a problem there, if that object which you will place as a reference in the script is already in the scene and is named “myObject” you might delete it, so make sure that reference you set is a prefab in your Assets folder somewhere.

—edit—
ohh my bad, i didn’t noticed at first read the “instantiating that game object into the scene”, therefore the object you will set as reference will not be in the scene. :slight_smile:

yup i will be linking a prefab that i want to instantiate into the scene and then later destroy =)