General Game Structure

Hello all,

I started working with Unity about a week ago. I have been doing C#/.NET/WPF programming for the last 2 years or so. As such, I became accustomed to a general “correct” way of programming, at least in WPF (SOLID principles, binding, MVVM, etc.).

Now in Unity, things seem a little more, ambiguous? As in, there are many more accepted ways of designing. Probably because many games can be so different from each other. It has been a little overwhelming. I have navigated various tutorials and documentation to try and find some type of structure but am still a little lost in places.

So I just wanted to break down some general game structure questions I have about scripting in Unity. Given a basic game structure with a Main Menu that may have several options like Play, Options, Shop. And then a Game Scene that cycles through “Stages” with breaks in between:

  • What is the best way to use a “GameManager” class?

  • Is that best to keep track of persisting properties like the Player’s Gold and Level, etc. and reload or switch Scenes.

  • Something like that is usually used in so many different places like when you defeat a monster, or purchase an item, so is creating a persistent singleton GameManager class that just follows Scene-to-Scene which other classes reference the way to go?

  • Should a GameManager know about Labels (like Gold, XP) and send the values to the GUI? Or is there a better way of doing that?

  • What do breaks between stages typically look like? Is it a UI element that you pop on screen until the User is ready to move on?

  • When creating multiple enemies or something of the sort, should you create multiple prefabs with adjustable properties (from Scripts) like Health, Attack, etc? And just switch out SpriteRenderers? I have seen some people use the SpriteRenderer as a Script property and keep the prefabs more general. But that seems a little more annoying.

I tried to keep the questions pretty general - I believe most of these apply to a lot of typical game structures. There still may be differing opinions on this stuff, but I’m hoping for some type of consensus so I’m not outright developing with poor practices. Thanks in advance!

  1. well this is 3 questions
    a) sure, that’s one way of doing it.
    b) yeah, singletons are common for persisting this data from scene to scene
    c) usually not, the GameManager is most likely a singleton, so let the UI just poll that information from the GameManager. If the data is volatile, you could consider the GameManager dispatching a ‘data set changed’ event of some sort

  2. that’s up to you… you could just fade to black and back in. You could have a complex load screen. There’s a lot. Haven’t you ever played a video game? Everyone puts their own flare on how to deal with scene progression.

  3. This is an extremely nuanced topic that really depends on your specific needs and what works for your enemy assortment.

1 Like

Thanks for reading and replying!

In terms of the loading screen, I guess I was thinking of something with multiple options, like upgrades, shop, etc. Which now sounds like a Parent container with various sprites or GUI elements.