Closed shadowmage45 closed 7 years ago
Try switching it from prefabTransform == null
to (object)prefabTransform == null
and see if it still functions correctly. Checking null directly on some Unity objects involves a lot more than just seeing if the reference itself is null (such as checking if it's been destroyed by the game, because the native Unity stuff is weird), and that can add additional overhead for the cases where it isn't null. If you don't need that functionality, cast it to object first for performance improvements.
Noted, and will do.
Good point on the null-check, as in this case it really only matters if it is actually a null reference as there shouldn't be any destroyed-yet-uncollected references on the prefab.
I wasn't aware that there could be a performance improvement from additional casting, but in this situation you are likely correct; the Unity derived equals/null overrides come at a higher penalty than the casting, and casting upwards to a base class is usually fairly cheap anyway.
Will get this updated after I get home from work this evening.
Out of curiosity, would object.ReferenceEquals(prefabTransform, null)
have the same effect of avoiding the Unity internals?
Have updated with the (object) cast and the null-check still appears to function properly.
@blowfishpro I have no idea, I suspect yes. Probably should get some profiling in to see if there is a difference in performance.
@shadowmage45 Alright, I'll merge it when I get a chance to test it myself. Thanks.
For cases where transforms do not exist on the prefab (procedural/modular parts).
PR-fix for #148
Please let me know if anything needs changed/fixed.