Home > Software engineering >  Optimization in Unity GameObject method calls
Optimization in Unity GameObject method calls

Time:12-11

Releasing game to Prod

I am finished with all components of my game and now I am wondering if it is okay to use FindObjectofType too much? will there be a bad result of using this method?

I tried using FindObjectOftype method in everywhere whenever I need don't know if it will affect the performance of game or not

CodePudding user response:

It is usually ok to use that method. But do not use these methods in Update(). consider using it in Start or Awake method.. According to Unity's 'General Optimizations' you should avoid using 'Object.FindObjectOfType' method in production. Since this method requesting UnityEngine to iterate over all GameObjects and Components in memory. Which will cause undesirable drain on performance.

  • Related