#Singletons
1 messages · Page 1 of 1 (latest)
I'd avoid making a single "god object"
you'll wind up with a ton of random features glued together
Here's all of the singletons in my stealth game.
there is a "game manager"; its job is to signal when the game enters different phases
like dying
having several components that do separate jobs all on one gameobject is fine
it doesn't really matter where these things live
they just have to exist somewhere
as I see it, a singleton is basically just a global object, and will destroy it self upon being created if another already exists, right?
The second half is just a nice safeguard
here's my singleton class
using UnityEngine;
public abstract class Singleton<T> : MonoBehaviour where T : Singleton<T>
{
private static T _instance;
public static T Instance
{
get
{
if (_instance == null)
{
_instance = FindObjectOfType<T>();
}
return _instance;
}
}
}
but what is the difference between a singleton and a so-called "god object" then?
public class NoiseManager : Singleton<NoiseManager>
a "god object" is just something that's responsible for way too much
yes, everything is an object :p
it's the "god" part that's the problem
for example, my enemy class had 2,500 lines of code in it and handled WAY too many random things at once
i'm refactoring my game to split that up
okay
ive read some things
seen a video
So I think I know just enough about Singletons to say: It'll be something to worry about another time
As I've not spent more than 10 hours making Unity games yet, I think if it works, it works yk haha
Proper ways to go about doing something, will just come along the journey