O'Reilly logo

Unity 4.x Cookbook by Matt Smith, Chico Queiroz

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required