Avoiding the Find() and SendMessage() methods at runtime

The SendMessage() method and family of GameObject.Find() methods are notoriously expensive, and should be avoided at all costs. The SendMessage() method is about 2,000 times slower than a simple function call, and the cost of the Find() method scales very poorly with Scene complexity since it must iterate through every GameObject in the Scene. It is sometimes reasonable to call Find() during initialization of a Scene, such as Awake() and Start(), only for objects that already exists in the Scene. However, using either method for inter-object communication at runtime is likely to generate a very noticeable overhead.

Relying on Find() and SendMessage() type methods is typically symptomatic ...

Get Unity 5 Game Optimization now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.