Advertisement

Question about player item inventory management in Unity

Started by February 02, 2019 07:25 PM
3 comments, last by Zakwayda 5 years, 9 months ago

Brand new at creating games. When creating items to be equipped to a player in an RPG style game, how are the data and stats typically managed?

Here is a screenshot from a Udemy course. It covers how to create the inventory panel but does address how data for large numbers of items are best managed.

Say you have 30 different swords and 30 different shields. Do you create lists of these items inside a script in Unity? Or is it better to create them in an xml or spreadsheet and port it using linq or something like that? How do you set up and manage the all of the item stats for these types of games?

Thank you!!

Screen Shot 2019-02-02 at 2.18.39 PM.png

This is my placeholder signature

We have had our item database made as ScriptableObject in unity where we stored Name, ID, Type Flags, Mesh and Buffs/Debuffs for our items. Items were stored in inventory as a chunk of ID and condition data (the remaining health of a sword for example) and were stacked if possible.

Our interaction system then offered points of interaction. These were models in the game world that checked the player in certain distance if they become faced and what it's active item (the item in it's right/left hand slot) is. The actor then sends an action request to the item that performed it's action on the actor (like decreasing a tree's health when cutting it down with an axe)

Advertisement

Class inheritance can be your friend here.  Inherited classes make your life so much easier.  Your inheritance tree may look something like this:
 

Item
    Equipment
        Helmet
        Armor
    Weapon
        Sword
        Crossbow
    Consumable
        Status Effect
            Strength
            Poison
        Healing

13 hours ago, jbarrios said:

Class inheritance can be your friend here.  Inherited classes make your life so much easier.  Your inheritance tree may look something like this:
 

Item
    Equipment
        Helmet
        Armor
    Weapon
        Sword
        Crossbow
    Consumable
        Status Effect
            Strength
            Poison
        Healing

Not disagreeing with you or trying to be contrary, but setting aside the issue of how relevant this is to the OP's question, I think it may be debatable whether this sort of hierarchy would be desirable or would make things easier. It can be a contentious issue, but I think there's been a move away from this sort of rigid inheritance-based approach towards data- and/or composition-based solutions.

A common argument against this sort of hierarchy is orthogonality. For example, what if you wanted a magic sword that could only be used once? Would it derive from 'Weapon', or 'Consumable'? A hierarchy like the above wouldn't easily accommodate something like this.

Anyway, I just thought it might be worth offering an alternative perspective.

This topic is closed to new replies.

Advertisement