null GameObject

Hello, tell me, please, I have a Gameobject variable in my code, it is empty, an object will be added there during the game.
How do I make sure that there is no error due to the fact that Gameobject is empty?
I searched the Internet, but I didn’t find any clear information for myself.

Make sure the variable is not null before doing something with it:

if (myVariable != null) {
  // Do stuff with myVariable here.
}
3 Likes

Use the implicit conversion UnityEngine.Object to bool.

if (obj) // obj must be a class derived from UnityEngine.Object
{
    // the object exists.
}
3 Likes

Thank you all for your help :slight_smile: