Jump to content

(Item) Managers - A Source of Pain in Life and in Code


Recommended Posts

  The next journey that I'm working on at this moment is the inventory system. I believe I've worked out everything that we'll need going forward. The first thing is that I'll be using a system not unlike Ragnarok Online to track the different items. We will have two kinds of enums to relate to every item. The first is their SuperType, thing of this like food, crafting goods, equipment, etc. This is used for filtering and not much else. The second, and much more important, is the SubType. This is the precise item that we are tracking. An Apple, Rose, Leather Jacket, etc.

  Unity has an annoying quirk where it will not serialize a dictionary. But we really want to use a dictionary for the item tracking. This is because we can use that SubType as the "key" to look up our data, and the item's information will be the "value" from our dictionary. So what I've done is created a system that synchronizes a dictionary and a list. The list is used in editor only for visualizing the contents of the player's inventory while I work and the dictionary is used at runtime and in builds.

  With this now achieved we have our dictionary of our items. So each item is a Datum, and the dictionary object is our Database. Finally I have created some ScriptableObjects (which I call Artifacts) to store this data in a nearly tangible way. By that I mean I can trivially take this object and attach it to other objects in the project. In this way our inventory can have a pointer to the same information without needing to double the amount of data present.

  Now that we've created our asset, the asset collection, and the linking system, the next thing I will need to accomplish is actually incrementing your values. We will be doing this with a demonstration cube. Tomorrow I will be hooking that up and maybe we'll have a simple gif or two to show off the work happening.

  That update will also cover a bit of the concept of "pooling" in my projects.

Link to comment
Share on other sites

  • Create New...