I have a basic question about the best way to handle a bug like this one…
Hi
The error you get means that you try to access the deleted object with your reference to it.
Your error is like this
Gameobject obj;
....
do soth. with obj
When you then delete the GameObject that is referenced by obj then you get this error when you try to access it.
To avoid this you can add this simple line of code into your script.
GameObject obj; //Your reference
....
if(obj) //This here checks if the referenced object exists
{
do sth with obj
}
When you destroy a object your reference to it is automatically set to null and you don’t have to unload the reference manually.
The reason is that your reference is a pointer to the object and so when you delete the object the pointer points to nowhere but you don’t need to unload the pointer to make it point to nowhere.
I hope this helped you to solve your problem
By
4 Likes
that did it! thanks so much.