Not equal to null does not work

The following code:

GameObject gmObj = (GameObject) NetworkedList[objId];
if (gmObj != null) {
   smObj.SendMessage("ReceiveTransform", theData);
}
else {
   DebugPrint("****ReceiveTransformToObject move object  but id='" + objId + "' not found, from " + fromUser.GetId() + ", NetworkedList[objId]=" + NetworkedList[objId] + ", gObj=" + gmObj);
}

produces

****ReceiveTransformToObject move object  but id='CK298-180' not found, from 362, NetworkedList[objId]=UnityEngine.GameObject, gObj=UnityEngine.GameObject

NetworkedList is a hash table.

Any idea why “gmObj != null” does not work? gmObj contains a GameObject which I think is not null.

Is there another way to check for object existence?

If it wasn’t null, the if statement would work just fine. I’d check whether or not your table is working and whether or not you’re storing items in it successfully.

To make it obvious, Debug.Log(gmObj.ToString());

You can also check if a key is present in a Hashtable using the Contains method.

The key is in the table. The variable gmObj is non-null as the debug statement showed, but the null comparison failed.

I restarted Unity and it now works, hopefully for good. Admittedly, this leaves me rather uneasy about the reliability of Unity.