Create a reference of a object in script and keep it even if the object is deleted

Hi

I am trying to make a reference object in a script so I could use it multiple times but I have encountered a problem. If the original object gets deleted it deletes the reference object.

This is my code.

GameObject tempObject = null;
tempObject = selectedObject.gameObject;
spawnObject = tempObject;

It is very simple as you probably can see.

Any help is appreciated with this! I am also sorry if there’s a lack of information but I don’t really know what else I could post.

You should use Instantiate to create clone object.

GameObject spawnObject = Instantiate(selectedObject.gameObject);

Object.Instantiate