here's why you should be careful and probably not ever use it with Unity objects. blog post by @lucasmeijerhttps://blogs.unity3d.com/2014/05/16/custom-operator-should-we-keep-it/ …
-
-
Deze collectie tonen
-
anyway here's me using it with Unity objectshttps://twitter.com/FreyaHolmer/status/1180449192902303745?s=20 …
Deze collectie tonen -
for more useful yet dangerous operators (that don't work well with Unity objects), check out the null conditional operator!https://twitter.com/FreyaHolmer/status/1082680949664612358?s=20 …
Deze collectie tonen -
and if you really want to use these operators safely with Unity objects, here's one way to do it!https://twitter.com/FreyaHolmer/status/1180472132565962753?s=20 …
Deze collectie tonen
Einde van gesprek
Nieuw gesprek -
-
-
Hi Freya, I was wondering: are these three variants the same compiler-wise ?
-
Generally I believe so yeah, unless the types have an overridden equality/inequality check, like Unity objects, in which case the first one will not use the overridden check, but the latter two will otherwise I think they compile to the same code!
- Antwoorden weergeven
Nieuw gesprek -
-
-
You can also use variable?.Foo() Lots of fun when it doesn’t melt down from unity bloat
Bedankt, Twitter gebruikt dit om je tijdlijn te verbeteren. Ongedaan makenOngedaan maken
-
-
-
Thanks for these null tips. I would like to add that relying on null as a significant value may be a bad design. Null should represent a non-initialized object or an unexpected situation in most cases, in my opinion.
Bedankt, Twitter gebruikt dit om je tijdlijn te verbeteren. Ongedaan makenOngedaan maken
-
-
-
Like you said in the thread, ?? is kinda not safe with UnityObjects. So throughout my code, i use something like: Health hp; hp = hp ? hp : GetComponent<Health>(); Would that be ok? Any weird gotchas there?
-
This one should be fine given Unity's implicit bool cast which in and of itself do a null check! your code is equivalent to hp = hp != null ? hp : GetComponent<Health>();
Einde van gesprek
Nieuw gesprek -
Het laden lijkt wat langer te duren.
Twitter is mogelijk overbelast of ondervindt een tijdelijke onderbreking. Probeer het opnieuw of bekijk de Twitter-status voor meer informatie.
Shapes
Shader Forge
Budget Cuts
ex-co-founder of
totally not a furry
wild shader sorceress
...math influencer?
twitch partner
info in thread)