Correct way to determine if a variable has a value

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.

Your first two methods are correct and won't generate any warnings or errors. The third method will compile, but will never execute the code between the braces no matter whether myWorldObj is assigned or not, and if you're using C# you should get an unreachable code warning. Any errors you're getting while using the first two methods are the result of something elsewhere.

the warning that you see is not for your current state of your game. just hit the clear button of log window. :) the message is for your previews code. use first or second method and you are good to go.