It doesn’t check that the object is null, but rather if it is active.
This caused hour of debugging to figure out where I was going wrong here by using “if (obj)”.
Is the lesson to avoid implicitly relying on “if (obj)” when possible, or is this just unusual programming done in the asset?
It may just be because I like strong typing, but I’d never write something like if(object) instead of if(object == null). It gives me more control over what’s actually happening, and I think it’s more apparent what I’m trying to do.
EDIT: How hard would it have been to make a simple isActive() instead? Cut down hard on the confusion.
An equality operator should be checking for equality, period. The whole “but, but floats… shouldn’t compare those for equality” argument is a bad argument for mucking with equality at the operator level. A better decision would have been to provide a Vector3.Approximately function like they did with floats.
This cost me two days of debugging which I ranted about at the time, but it would be dangerous for them to change it at this point.
I actually had written my own Approximately method for vectors, assuming the equality was actual equality (an operation I would never have used…), then when looking at the source code of UnityEngine.dll one day I tripped over that and was like “what? really guys? it’s bad enough how you abused the == null and implicit bool of UnityENgine.Object… but this, this takes the cake.”
That was pretty much my reaction too. At least the behavior is documented though. I wouldn’t ever generally use it either, but the “set value and do stuff only if the new value is different” thing does come up occasionally.
You know Unity overides == too, so it’s not doing what you think it is.
I actually prefer to use the implicit book when I want to know if an object exists in the scene. That way I cant accidentally call the regular == null when I want the unity == null.
While we are talking about bad decisions, my favorite pet peeve is the implicit cast from a Vector3 to a Vector2. This cast looses information, and so should require explicit casting. Plus it makes Vector2 + Vector3 fail, making it relatively useless anyway.