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