I used to look for and cache references to other GameObjects from 1 main Awake() function, for example in my HUDManager class, I would search for all my HUD GameObjects in its Awake() function and cache them to separate variables.
Since then, I created a new class called “SelfRegisterToManager” which takes the GameObject it’s attached to, and “Registers” it to the chosen Manager. I put “SelfRegisterToManager” on all my HUD GameObjects, and in its Awake() function, I call the chosen Manager’s “Registering” function and cache the GameObject, for example:
// On my Camera HUD object
Managers.HUDManager.RegisterGameObject( this.gameObject, hudType.CAMERA, this.gameObject.active );
// On my Laptime HUD object
Managers.HUDManager.RegisterGameObject( this.gameObject, hudType.LAPTIME, this.gameObject.active );
// On my Menus HUD object
Managers.HUDManager.RegisterGameObject( this.gameObject, hudType.MENU, this.gameObject.active );
// On my PowerUp HUD object
Managers.HUDManager.RegisterGameObject( this.gameObject, hudType.POWERUP, this.gameObject.active );
// etc...
So, every HUD object that has the “SelfRegisterToManager” script attached to it calls the “RegisterGameObject” function from whichever Manager it is talking to, and caches itself.
Lately, I have noticed that my level load times have increased, and I am wondering if it is related to how I am “caching” objects now, using the “SelfRegisterToManager” class? Like I said, before, I used to do all the caching in the Manager’s Awake() function, and now, I do all the caching from each object itself…which is the same amount of lookups, but not all in 1 place.
I hope I was able to explain what I’m doing and what I am asking without too much confusion…am I slowing down my level load times by caching my HUD objects this way, compare to caching them all in the Manager’s Awake() function?
Thanks for your time!
Stephane