- Home /
How to stop Unity from destroying prefab original when destroying copied instances?
Hi everyone,
When I try to delete an instantiated (copied) Transform object from Unity, it deletes the original prefab also. When I try creating a new instance from the prefab again, I receive the following error:
MissingReferenceException: The object of type 'Transform' has been destroyed but you are still trying to access it.
Your script should either check if it is null or you should not destroy the object.
The copied objects are created with the Instantiate method with the original Transform in it:
Instantiate(laser, new Vector3 (posX, posY, 0), this.transform.
rotation);
The Destroy method is called in collision check method and gets the game object for destroying:
Destroy (theCollision.gameObject);
Any advice will be helpful.
Answer by Owen-Reynolds · Mar 27, 2015 at 10:30 PM
Unity doesn't do that (doesn't destroy the original prefab if you destroy a copy.) Somewhere you are destroying the original.
If laser if the prefab, somewhere you are doing Destroy(laser);
. Or something like GameObject z=laser; Destroy(z);
. Or maybe the original isn't really a prefab -- it's in the scene and you are destroying it. You could print the name of each thing you destroy, just to check.
Answer by VirtualLife76 · Dec 09, 2021 at 08:46 PM
I realize this is old, but had similar confusion. To completely separate a prefab, what I did was duplicate the prefab, drag to the scene, right click on the object -> prefab -> completely unpack -> drag to prefab. This way 1 prefab doesn't affect the other.
Fairly new, but your question came up 1st in my search, so hopefully it will help others.