Checking Instantiate/Destroy has been called | Checking number of scene GameObjects

Hello.

Is there a way to check the number of all game objects in the scene, or to check if Instantiate() or Destroy() has been called, without putting an extra line to every script that does that?

It would help a lot to increase the performance, as I have some scripts that search the scene for specific objects. This way I would not need to check every frame, instead, I’d tell the script to scan again only when needed.

Thanks,

Luka.

You could hold a Singleton GameManager type class. Everytime an object is Instantiated you could add the reference to that GameObject in a global GameObject array. Then when that object is destroyed you’d remove that object from the global GameObject. This would only require you to write your own Instantiate and Destroy methods which would basically just do that list add/remove and would give you an array with reference to every GameObject currently in your scene.