Hi !
I’m planning to work on a survival-horror game, and I’m thinking about how I’ll be organizing the data. Survival-horror implies that the save system will be quite important, because of all the key items, the different states of the doors, etc.
At the moment, I’m scratching my head over items. When I think about it, it really comes down to the same issues that I encountered in a previous project, that was a card game : how/where to design the behaviour of some objects.
How I did it in my previous Card Game project :
In this previous project, every element had a Data part, that inherited from GameElementData : ScriptableObject, which held basic info such as ID, Name, Description, and Flavor Text. All my cards had a CardData : GameElementData.
I also had a plain C# class called Card, constructed with the CardData to initialize it. This class has a CardBehaviour property, which is an abstract class.
These cards were created by a Factory, which had a Dictionary<string, Type>. This means that depending on the ID, the Card’s CardBehaviour was set to an instance of the corresponding type.
Now, this has 2 aspects that feel hacky to me : this is prone to spelling error, and the dictionary has to be initialized “manually”.
Another approach that I used in the Card Game project :
In this same Card Game, the players could unlock items.
For this part, what I did was creating Monobehaviours, inheriting from an AbstractItem class and exposing an ItemData. I then created a GameObject for each of them, which were referenced in an ItemFactory as prototypes in a Dictionary<ItemData, AbstractItem>.
This way, when an item was requested, the Factory would Instantiate the corresponding one in the Dictionary.
This feels a bit cleaner, but I’m concerned about having a prototype of each item in the game as a GameObject. This seems really heavy for such a purpose, but had the advantage of being pretty straightforward and initialized at runtime.
My current question(s) :
Where should the behaviours of my objects go ?
For the inventory for example, I ultimately only need to keep track of which items does the player have, and in which quantity. So it could really boil down to Dictionary<ItemData, int> if we think about it.
But what if my player decides to use an item from the inventory : should I instantiate the behaviour at this very moment only ? Or should the inventory hold instances of an Item class, which has a Use() method ?
Should I try to use plain classes, and ultimately use Unity mostly as a view, or should I embrace the GameObject/MonoBehaviour and have actual instances of my items in the scene ?
I suppose that this applies to a lot of cases : abilities, weapons, cards, skills, items. Most of what I see online is very beginner-oriented, pure Scriptable-Object “architectures”, that do not scale well in my opinion.
My current takeaway from my previous experience is that I should use Scriptable Objects for data mostly (if not only), and put the behaviour somewhere else. I just struggle to decide what should my items be, and what would be part of a “decoration”.
Thanks a lot for reading me !