General Optimizations Flashcards
Address Properties by ID
Unity does not use string names to address Animator, Material and Shader
properties internally. For speed, all property names are hashed into property IDs, and it is these IDs that are actually used to address the properties.
Use non-allocating physics APIs
Replace RaycastAll calls with RaycastNonAlloc, SphereCastAll calls with SphereCastNonAlloc
Find and FindObjectOfType
It is a general best practice to eliminate all usage of Object.Find and Object.FindObjectOfType in production code.
Camera locators
Internally, Unity’s Camera.main property calls Object.FindObjectWithTag, a specialized variant of Object.FindObject.
Debug code & the [conditional] attribute
The UnityEngine.Debug logging APIs are not stripped from non-development builds, and do write to log files if called. As most developers do not intend to write debug information in non-development builds, it is recommended to wrap development-only logging calls in custom methods