How to check whether the object is exist?

Hello all,

I am storing the objects which is collided by a ray from the screen.

//lockedObjects is an Array of GameObject type
lockedObjects[lockedObjectsCount-1] = hit.collider.gameObject;

But during the game play, some of the objects are destroyed by colliding with each other. By the time, I tried to access those objects, it is saying this.

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

Give me suggestion how to check for whether the GameObject I stored in an array is still exist?

Thanks in Advance.

There’s answer right in the error log you’ve provided: “Your script should either check if it is null or you should not destroy the object.”.
You should check if object is null before trying to access it.

I tried using if(object != null).

But it still showing the same error…