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

Question on Scriptable Object inventories

Discussion in 'Scripting' started by Flynn_Prime, Jul 11, 2020.

  1. Flynn_Prime

    Flynn_Prime

    Joined:
    Apr 26, 2017
    Posts:
    387
    Hi, so I have recently been watching different videos, and reading different tutorials regarding creating an inventory system using scriptable objects. I'm comfortable with how to create an inventory system myself, but scriptable objects are still fairly new to me. One thing I kept noticing in these tutorials is that they were still using an ItemDatabase (a scriptable object dictionary of items usually) to store items. My question is why? Scriptable objects can be referenced directly by anything cant they? This doesn't really make sense to me right now, and I'm sure I must be missing something...
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,888
    You can use ScriptableObjects to hold data about items, but only if that data doesn't change during your game. So you can think of them as "item blueprints". For example you can have a "Small healing potion" Scriptable Object that stores its price, how much it heals etc. But any data that changes in the course of your game and you need to persist across playthroughs, that has to live elsewhere. For example, your player's "inventory" of items cannot live on ScriptableObjects. They do not persist their changes across play sessions.
     
  3. AntonPetrov

    AntonPetrov

    Joined:
    Dec 27, 2013
    Posts:
    63
    Hi!

    I do not know exactly what video you talk about, but I have ItemDatabase to reference all possible items there so that I could resolve items by their ID (or name). Otherwise, without the ItemDatabase Unity will strip out all non-referenced items from your final build.
     
  4. Flynn_Prime

    Flynn_Prime

    Joined:
    Apr 26, 2017
    Posts:
    387
    Perfect, its as simple as that. Thank you. Although, why would you even want a non-referenced scriptableobject included in your build? Hmmm...

    Thanks for your input, but wasn't quite what I was getting at. Sorry if my original post was unclear.
     
  5. AntonPetrov

    AntonPetrov

    Joined:
    Dec 27, 2013
    Posts:
    63
    My game is online so it is possible to receive a server command containing the ID of an item that was not referenced from existing Unity scenes.

    Or you can have some text data files (JSON, XML, etc.) which can have textual references to your items but Unity knows nothing about it.
     
    Flynn_Prime likes this.