Just want to chime and say thanks, this was very helpful. I have a big passion for RPGs, but am still (after 7 years of Object-Oriented Programming) baffled by making larger projects (10,000 - 50,000 C# lines, or more).
For my code, it tends to get super complex, not easily maintainable, not easily changeable, etc.
Also another big problem is over 80% of the changes in the future have to go through me, the programmer, instead of my sister (the designer/artist).
I recently started getting into Programming Design Patterns (big thanks to https://gameprogrammingpatterns.com/) and also watched this Unite 2017 talk on ScriptableObjects.
Brief Summary:
From the Unite talk, they create this abstract ScriptableObject class with a generic type , so that you can choose to refer (in the Inspector) to any shared variables you want. Say you wanted a shared integer (like the player’s HP) accessible across your project – you can make a simple ScriptableObject instance that just stores that integer.
My Problem:
But what is really confusing me is how to expand that.
It’s great we have this designer-friendly shared integer value that any script in the project has immediate access to, however…
1. Where should I incorporate HP clamping? (Making sure the HP stays within the range of 0 to their MaxHP)
- This doesn’t apply to all variable types, just maybe integers and floats, so this definitely doesn’t belong in the abstract superclass with the generic type .
2. Where does the MaxHP get stored, if this is just its own integer in a single ScriptableObject?
- Does it break code re-usability if I start using more custom data types to store HP, stats and etc., or make the code more stiff, relying on concrete data types?
3. Where should my damage function live? Should it be on my MobController (MonoBehaviour class)?
- But then I can’t easily call damage on the HP ScriptableObject…
- I also wouldn’t want to put damage logic in a general integer/float ScriptableObject class, since it’s specific to HP (not all integers/floats).
For context, this function would be used to calculate damage based on a variety of factors that may change in the future, based on the type of attack, element (if any, like fire, water, etc.), the 2 mobs involved, etc.
I know this is all subject to my own design, and probably the game systems that I actually want to make. But I’d seriously appreciate any insight or advice!