#I m still just trying to parse the bits
1 messages · Page 1 of 1 (latest)
Lets move this here since it's above the normal #💻┃code-beginner stuff
You mean line 88?
Just saw this. Sorry. One sec.
It casts the passed object as an object, then it checks if that object is null && NOT null && NOT an object and... for fuck's sake... what is going on there...?
Line 92.
Basically it's the way they check if the object is null, since they don't know what type the passed parameter other is
OH!
The first check is to check if the thing you passed is an Object, but that object is null, e.g. it was destroyed
e.g. myGameObject1 == myGameObject2 where both are destroyed game objects
Gotcha.
Second two checks are just if you explicitly pass null
But I agree it is weirdly written
It's probably efficient, but it's quite difficult for me to parse.
In general everything having to do with the interop to the C++ side isn't terribly efficient
That's why someone mentioned you should be pooling objects anyways
I get 'if object is null, return false'. It's the stuff afterwards... =/
You mean the CompareBaseObjects method?
Oh, I'm big on object pooling. I have a healthy fear of the Garbage Collector.
return false;```
Everything in that line past the first &&
So, it's like... "If the cast to object fails, and a NULL wasn't passed to this function and the other isn't a Unity Object, return false".
Okay. I think I get that. Thank you. =D
Basically it says: if the thing we passed is null (meaning it is a destroyed object or we passed null), and we didn't pass null (second check), and the parameter isn't an Object, there is no possible way they are equal
So it early-outs to false
Otherwise it uses the CompareBaseObjects method to handle the other cases, e.g. this is actually already destroyed, etc
Big fan of early-outing, just staring at that text and willing it to fit in my head.
I get the otherwise just fine. =)
I think one of the things that confused me was that the function parameter was for 'object', but I'd forgotten that due to inheritance I could basically pass anything in there.
I'm kind of confused why this isn't just a normal equality check, with UnityEngine.Object as a parameter
Since gameObject == 5 is never going to be true
This is very much turning into https://www.youtube.com/watch?v=AbSehcT19u0
I think this is pretty familiar for most of us.
To everyone who watches this: please check out this youtube creator called nartharie . He has created some of the must absurd and funniest videos I've ever seen, but he's still at 280 subs at the time of writing. So please discover this before all your friends or acquaintances or whatever do and be...
I might just put my hands up and back away slowly.
Yeah, the takeaway is just to use no fancy C# features when checking UnityEngine.Object lifetime
e.g. something like ??= will also not work afaik
Which I guess would also not make any sense for an UnityEngine.Object since they can't use a normal constructor
I don't even know that. =D I just was wondering if was actually bothering to do something complex when comparing AND I GUESS I HAVE MY ANSWER--!