Why is GridSystemVisual a Singleton?

Up until now, the GridSystemVisual script is only used from places where we could easily drag a reference in from the scene. So I was confused about the conversion into a Singleton. Will we use the script from something like a prefab later in the course?

And related to this: what reasons (such as access from a prefab) do you consider valid for turning something into a Singleton in Unity?

The main question is do you want to handle the reference through the editor or through code? That’s really about it.
In cases where you’re not forced to use it, like if the object never becomes a prefab, then it’s really personal preference. Both approaches yield the same result.

Any object that exists only one can be a candidate for a singleton, whether you make it a singleton or just drag the reference is personal preference so use whatever method you prefer.

I don’t have any hard rules on that, sometimes I use Singleton if I want to access it through code (I tend to prefer this when working by myself), sometimes I drag the reference (I tend to do this more in tutorials to make the code simpler so I don’t have to constantly explain singletons)

2 Likes

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms