Hi there,
I did some research, but couldn’t find an answer for it, and it’s been bugging me for some time now. Anyway, please forgive the noob question, but here it is: Is more performant to use a script attached to an empty game object, which has all the variable instances the game would use, and then have all the other scripts use the instances from that script?
Let me try to be more clear:
I am trying to clean up a code for a game I’m working on using the SOLID principles, and in most scripts that I have, I noticed that in the awake() or start() function, I use instances such as Camera cam = Camera.main, or GameObject player = GameObject.FindGameObjectWithTag(“Player”), and so on. So I thought instead of having the instance of cam and player (and other variables I use in the game) repeated in different scripts, why not have them in a single script called ObjectInstances (which has only the awake function), so that other scripts can use the needed variables from this ObjectInstances script.
This way, all the game variables would have a single instance in the whole game, and the ObjectInstances script would have an instance once in all the other scripts.
Now, that being said, here are my concerns:
-Is this way really more performant than having in the game scripts all the instances they need, even if they are repeated (between different scripts)?
-Are there some foreseeable problems that you know this way of coding will create?
-What about the impact on the memory usage?
Any feedback or help would be greatly appreciated,
Thank you