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 to use ScriptableObject for Inventory System

Discussion in 'Scripting' started by Narmer, Mar 1, 2015.

  1. Narmer

    Narmer

    Joined:
    Mar 5, 2014
    Posts:
    25
    Hey, guys. There are two ways that came on my mind and I think both of them have some pros and cons:

    In both ways I have Item class that derives from ScriptableObject and several subclasses (such as Weapon, Jewelry) with various functionality.

    A) Make a Dictionary of Instantiated ScriptableObjects

    dictionary.Add("name", ScriptableObject.CreateInstance("Weapon", otherVariables,...);

    (so dictionary with around thousand entries) And when I need specific item I just search in the dictionary.

    B) Make each Item as a separate script

    item1 = ScriptableObject.CreateInstance("Item1"); item2 = ScriptableObject.CreateInstance("Item2"); The pro here is, I would be creating instance of only those items I actually need in the moment + better flexibility in general.

    The question is what is better solution concerning performance and other things? I went for solution b, since it seemed to me more flexible way.