Destroying an object with the same name twice.

Hello,
I am having a problem where I am trying to destroy an instantiated object multiple times right after it gets re-created with the same name again. I have even printed out the object that I am trying to re-destroy and it is not null, but when I call Destroy() on it, it says

MissingReferenceException: The object of type ‘GameObject’ 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.

I already did check and it does not print out null before the object gets destroyed more than one time. Destroy() seems to work ONCE on an object with a specific name. Then, if it gets instantiated again with the same name, I get problems destroying the object. How do I fix this? I also notice that when I double click on the error message, it does not take me to that line.

Thank you,
Michael S. Lowe

Keep a reference to the instantiated object instead of trying to find it by name.

Also it’s really hard to give any specific help without any code, especially with null-refs.

Use if condition for that:

csharp code:

GameObject temp=GameObject.Find(“yourObjName”);
if (temp)
Destroy(temp)