Cover by Matt Smith, Chico Queiroz

Safari, the world’s most comprehensive technology and business learning platform.

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required

O'Reilly logo

Caching, rather than component lookups and "reflection" over objects

Optimization principal 5: Minimize actions requiring Unity to perform "reflection" over objects. Reflection is when at run-time, Unity has to analyze objects to see whether they contain a given set of methods or components. An example of this would be the simple, useful, but slow, FindObjectsByTag(). Another action that slows Unity down is each time we make it look up an object's component, either explicitly using GetComponent(), or implicitly using a component accessor variable such as transform or renderer. In this recipe, we'll incrementally refactor a method, making it more efficient at each step by removing reflection and component lookup actions. The method we improve finds ...

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required