- Home /
Global references to important hierarchy gameobjects in singleton script, bad practice?
Often scripts in our hierarchy need access to things like the camera or the Vive controller or the UI canvas etc etc. Not a problem, make a public property in the script and drag & drop the desired gameobject on there, right?
Now we're starting to lean more and more to having such global gameobjects simply as public properties in 1 singleton script called 'Scene References'. Then whenever we need to access one of these objects, we call SceneReferences.Instance.MainUICanvas or whatever is needed.
This seems quite useful because now when we change one of those objects, we only need to update the reference in 1 place. Also, it's easy to see in code everywhere it's used through 'Find All References', something which doesn't work in the Hierarchy (so annoying btw!).
But of course this is using 'globals', which almost all programming docs say is not a good solution. Does anybody else use this same pattern? What are your experiences with this?
Your answer

Follow this Question
Related Questions
Composite Design Pattern in Unity, Redundant? 1 Answer
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
I have some question about custom Hierarchy 0 Answers
Best practice for passing data between classes in C# 3 Answers