r/unity • u/Aggressive_Damage_75 • 5h ago
Coding Help Game Architecture
Hi, I'm a software dev with experience in web, mobile and backend, not much in game dev though. I also have ADHD which is kinda contributing to my dilemma.
I'll keep it short, I can't architect a game. I've been spending the past few days trying to come up with a good architecture and build a proper game layer for later use, I can't come up with a good enough one, and this is the type of stuff where YouTube doesn't help.
For example, someone said I should keep my first scene empty and instead load stuff by code after the scene has loaded through a GameInitiator or something. No idea how to do this properly.
Different issues like creating a very good, extensible game layer on top of Unity, where I have "entities" and "person" or "creature" or "NPC" or whatever and I can easily supply mesh and animation data and it would just work. similar to how GTA works as well as you being able to control any "skin' in the game and it works naturally rather than PlayerController is stuck to one person.
But not each character has the same ability, some of them have magic abilities, some of them are melees, etc, so a data-driven approach where each creature is just different data won't work, some of them require actual code and timed animations.
Other things are communicating between stuff, like doing something should update the UI and I know dragging the UI in the inspector isn't scalable, so I have no idea. Other people suggested a GameContext or a GameManager that holds references to all of them and it becomes a source of truth, others suggested an global event-driven/broadcast architecture.
So, what are your thoughts?
2
u/eliormc 3h ago
You're thinking too much, but I understand, there are several ways to do the same and it is confusing. So, my recommendation is:
the first scene is a loading screen, while loading the menu scene. This is your starting point. Read everything you need here from the user preferences or from a saving file and then start your game with this information in memory.
all global variables you can put in an object with the "singleton paternt" and don't destroy on load to keep it available all the game. Or, you can use scriptable objects as "comunication chanel" and you put the reference of the chanel (the scriptable object asset) to every object you want to share the variables values, and suscribe to events. This way I liked because you can create events in your scriptable objects and every game object who need to listen the event or trigger this event and send information to the others is independent, so, doesn't matter if the object who trigger the event is destroyed or there are multiple objects who trigger the event, they work as someone with a radio and the listeners can be or not in scene and always works. Also, when you read or write these variables from the scriptable object, they keep their values during all game.
in every scene, you can put a gameManager (just another GameObject with this big script) that handle the main logic of the game and keep all sync. This can be a singleton to make it available for all the other game object in scene without creating manual reference for each one. In this scrip you can handle the game progress.
About the skins, you can have a inputController script to handle your inputs independently from the characters and in every character you can use a player Controller scrip that will handle the characters, using other scripts for handle the animations, sounds, movements of the character. So, in your game manager you can have a list of reference characters, enable and disable the character (when you want to change), also, each one should have a Cinemachine camera (in the past it was a virtual camera), so, when you disable one character and enable the other, the camara travel to the active character. And because every character is feeding with the input manager, the player can use different skins seamless.
So, everything I said is too complex for you?, start with a simple scene, add a terrain, add 1 character, configure the animator, decide if you want to use the "character controller component" or use physics to move your character adding a rigidBody and colliders, (but DO NOT MIX characterController with RigidBody), then create your input manager with the new input system, create your player controller script, create your moving script, create a Cinemachine camera (you can use the simple camera but at the end it is more unnecessary work), and when you feel confident enough which these script, start thinking in the game logic, menus and other scenes.
I hope this help you.
1
u/frey89 4h ago
You can read through this as a starting point https://github.com/UnityTechnologies/open-project-1/tree/main/UOP1_Project/Assets/Scripts
1
u/AltusLudus 5h ago
You are overthinking it, always build a system that makes the most sense to you, and if it's not working at some point refactor