Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

How do you guys typically store your object / item databases?

Discussion in 'Scripting' started by JoeyWeidman, Nov 15, 2019.

  1. JoeyWeidman

    JoeyWeidman

    Joined:
    Dec 30, 2016
    Posts:
    8
    Right now I'm using Scriptable Objects to store Dictionaries that have the object ID as the key, with the value being the prefab of the object. So it looks something like Dictionary<int, Item>. And I have multiple different SO databases for different types of objects, so another one could be something like Dictionary<int, Spell> The problem with this approach is that I have to validate that the dictionary keys correspond to the correct Item whenever I add to the database. (i.e. key == item.id) It just seems clunky to me.

    However, because all my item information is stored within a Dictionary, I imagine it will make saving and loading fairly simple. For example, if I want to save the player's current items, I only need to save a list of ints, each representing the ID of its corresponding item. When I want to deserialize it, I just need to reference the Item dictionary with the IDs.

    So I'm curious, what is your approach to storing your static object / item information? Any advice for my current solution?
     
    Last edited: Nov 15, 2019
  2. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,753
    Yep, just stir IDs as ints, and corresponding data, like health position, etc.