When I should use a singleton and when just GetComponent?
Hello people,
I'm new in the use of singleton and I find really useful to access them from everywhere in the project just doing Script.Instance.SomeMethod(), but I wonder "Am I overdoing it"?
So I would like to know if I am right in transforming every script of which I have just one instance in the project and I need to use its methods or reads its variables in a Singleton.
For example, if I have a script where I store all my configuration, is it ok if I made it a Singleton? Is it ok when, there is a user that is a master and in some part of my code I do:
if(Configuration.Instance.isMaster)
//do Something
Can't wait to know what you have to suggest me, thank y'all
When I should use a singleton
Well.... Almost never.
https://stackoverflow.com/questions/12755539/why-is-singleton-considered-an-anti-pattern
I find really useful to access them from everywhere in the project
It means you are about to use the Singleton in its worst form.
Your answer
Follow this Question
Related Questions
Elements of Listare null after loading scene 1 Answer
Start is not called after reloading the level 3 Answers
I didn't assign a value to the instance in singleton, but it is assigned automatically. 0 Answers
Frame Debugger shows draw mesh even though object is set inactive 0 Answers
CPU Usage ? 1 Answer