RPG Inventory - Creating unique item instances

Hello,

I’ve completed the RPG Inventory Systems course, and now I’m thinking about ways to expand the functionality that was taught in the course. One thing I would like to implement is a way for each instance of an item in the game to be unique and distinct, with the ability to modify one instance of the item without it changing the values of every other instance of that item.

In the course, items are represented by an InventoryItem ScriptableObject which contains various values that define the item (name, description, icon, etc.). Essentially everything in the game that deals with items refers to the InventoryItem script. Because of this, every instance of an item in the game is linked together and thus will always share the exact same properties.

For example, say you have a “Hat” InventoryItem and you spawn 5 of them in the game. The game doesn’t really treat these as distinct objects, it just refers back to its ScriptableObject to get its info. While playing the game, if I wanted to take one of the hats and modify it somehow (e.g. give it a new name, buff its stats, etc.), changing something on one of the instances would change all of the instances in the same way.

Ideally there would be a way to keep the InventoryItem ScriptableObject as a “base item” that can be used as a blueprint to spawn distinct items into the world, which could then be handled individually. I don’t know if there’s a way to augment the existing code to accomplish this, or if it would require a major refactor.

I hope I was able to explain the situation in a way that makes sense. If not, I would be happy to clarify. I feel like I’ve reached the limits of my Unity and coding knowledge with this problem, so I’m hoping some of you could help me out.

Thank you!

You can save item scriptable object as blueprint. And make instances of that item in game and change it at runtime. This is complex theme for several hours. I can only suggest you to get patience and watch https://www.youtube.com/watch?v=_IqTeruf3-s&list=PLJWSdH2kAe_Ij7d7ZFR2NIW8QCJE74CyT
and use this for your project or not.

The key to making your idea work is Instantiate(originalScriptableObject)…
When you do this, it will be a distinct copy, but still have the same ItemID… meaning when you save inventory, you’re still saving the ItemID that is the root SO… In this case, you’ll need to modify the Inventory save so that it saves the ItemID AND the attributes that are different… then when you restore, you’ll once again Instantiate the original SO and make the modifications as saved.

1 Like

We would need to add the attributes that are available to modify into the Item ScriptableObject, correct? For example, if there’s a +0 to +3 upgrade system, the SO by default has a field for “Level” at 0, but you could override and save that for a specific item within a struct?

Correct, you would modify the Instantiated SO, then when you went to save, you’d need to save the ItemID of the SO along with any modifiers.

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms