#I m still just trying to parse the bits

1 messages · Page 1 of 1 (latest)

timid cedar
#

You mean line 88?

rapid glen
#

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.

timid cedar
#

Basically it's the way they check if the object is null, since they don't know what type the passed parameter other is

rapid glen
#

OH!

timid cedar
#

The first check is to check if the thing you passed is an Object, but that object is null, e.g. it was destroyed

rapid glen
#

BECAUSE OBJECT COULD BE ANYTHING BUILT ON OBJECT.

#

I'm a moron.

timid cedar
#

e.g. myGameObject1 == myGameObject2 where both are destroyed game objects

rapid glen
#

Gotcha.

timid cedar
#

Second two checks are just if you explicitly pass null

#

But I agree it is weirdly written

rapid glen
#

It's probably efficient, but it's quite difficult for me to parse.

timid cedar
#

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

rapid glen
#

I get 'if object is null, return false'. It's the stuff afterwards... =/

timid cedar
rapid glen
#

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

timid cedar
#

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

rapid glen
#

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.

timid cedar
#

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

rapid glen
#

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...

â–¶ Play video
timid cedar
#

😅

#

I've never looked at this part of the C# code extensively so I have no idea

rapid glen
#

I might just put my hands up and back away slowly.

timid cedar
#

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

rapid glen
#

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--!

timid cedar
#

And if you are pooling anyways you can just skip all of these checks (at least the weird null checks)

#

😅