Let's say you have an item database which has every item in your game. This works fine for regular items like a Health Potion, a normal Iron Sword etc, because these items have ItemID's so we can get an exact copy of this item. But what if we have an Iron Sword with an enchantment: '+5 Fire Damage'? (or whatever)

If you were to save that item to a player's inventory, exit the game and load the game, the item will load as a regular Iron Sword, because it still has that ID.

Specifically, how would you save that item to a file? I'm using Unity, so to save the Player's inventory, I use:

PlayerPrefs.SetInt("Inventory " + i, inventory[i].ItemId );

Would you create a custom item ID for every item with enchantments or is there a better way around this?

  • \$\begingroup\$ You need to add some meta data to the save file. \$\endgroup\$ Feb 6, 2015 at 16:41
  • \$\begingroup\$ Word of caution: PlayerPrefs writes to the registry on Windows. \$\endgroup\$ Feb 6, 2015 at 16:41

1 Answer 1


From what you wrote I understand there is an existing Enum that represents all items.


small_health_potion = 1
large_two_handed_sword = 2
// etc

Now, considering you already have that system in place, you wish to extend it for items that are variations of these items like enchanted versions and perhaps cursed versions and what not.

The issue is that we don't know exactly what kinds of enchantments are available in this game. In your specific scenario, I would list the enchantments of each item, after it's Enum id.

for instance, if up until now:

helmet = 2
shield = 4
armor = 7
sword = 8

and the inventory would look like this:


Then I would add a list of enhancements:

armor+5def = 11
weapon+8atk = 37
wepon+7speed = 49

and simply do this


Inside a db, you can save the inventories contents as a varchar.

You can also store an enchanted item by storing a pair of item base type and enchantment type.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .