I'm running some code on a gameObject assigned through a variable in the Inspector. However in some cases there isn't a gameObject to assign, so I am attempting to double check first whether a gameObject has been assigned to the variable.
I have tried the different code snippets below, but I still get a warning: "UnassignedReferenceException: The variable myWorldObj of 'visualControl' has not been assigned. This happened in the game object..."
if(myWorldObj != null){
// do stuff with this object here
}
if(myWorldObj){
// do stuff with this object here
}
if(!myWorldObj == null){
// do stuff with this object here
}
I've successfully checked if components like scripts exist using GetComponent, but I don't know how to do it for individual values like this. My game runs fine, but seeing the warning at the bottom of the window upsets me.