Search Unity

Yet another inventory question from a dumb man.

Discussion in 'Scripting' started by TheJohnRudy, Oct 20, 2019.

  1. TheJohnRudy

    TheJohnRudy

    Joined:
    Oct 14, 2019
    Posts:
    9
    I apologize in advance for this relatively long winded question about to ensue but I just need someone to prove my theory or get some help getting me into the right path. This is the result of reading too much and not really getting it after a couple of days.

    So I wish to make a inventory (shocking...), but I do not want to make it grid based. I want to achieve a carousel like inventory system that is used in Silent Hill 1 using 3D objects that rotate around a central axis.

    image for reference

    Taken from a Unreal Engine forum from a user that is trying to do the same thing but in c++ blueprint form so I don't know if that can be translated into c#. Did I say I'm a noobie?

    I've noticed that there all ready is a shared script to achieve the carousel effect here that I can download and dissect to get the effect I want.

    The question becomes now on the basics of item handling, interacting and managing. I've now spent a couple of days looking into how items are created and handled and how people do it for RPG's and other grid based systems, but I get completely lost whenever they start creating scriptableObjects and not really explaining what they truly are on how they are called when accessing an inventory. I can understand the fact that you can create a .asset file and just use that to (instantiate?) populate the game level with items with low effort.

    So my line of thinking right now is this

    1. Have a database/list of all items.
    2. Get values, names, descriptions and amounts from that database for the items. (scriptableObjects?)
    3. Create a prefab of the specific item and world model. ( or is this the scriptableObject?)
    3.a. Have the item prefab have the interaction code in it i.e. input.getkeydown(yada yada yada) call boolean from the player to play "pick up this item" animation and overlay UI saying "You got this weird thing, aren't you happy?"
    4. Place that picked up item inside a inventory list. A new list. Not the database of all lists and use the same world model for the carousel.
    5. When player presses the inventory key call an array and populate that array with the picked up items in a 360 degree array. (see above carousel and image reference).
    6. When an item is used remove the item from the inventory list. Get updated carousel.

    In the end I would have in theory 4 scripts (Database, Inventory, Carousel and ItemPickup) and a prefab for each item with the ItemPickup script embeded.

    Truly this is becoming a multipart question right now. I'll numerate them too for easier understanding.

    1) Is this line of thinking right?
    2) Which part of this is the scriptableObject or should I just do it differently?
    3) Is the database a plaintext file of row's and colums of item information or am I just insane.
    4) This is how all items should be handled? i.e. Health, key items, ammunation? Or should all three for example have their own subset of item declaration. As in Items/Health - Items/KeyItems - Items/Ammunation etc. etc. inside the database or SO.

    Thank you in advance. Sorry for the long read and the possible headache.
    P.S. I've searched these forums and others for a while not really getting a clear answer. Possibly because I don't get a simple interaction or that the question differed in someway that didn't work with my view.
     
  2. Shack_Man

    Shack_Man

    Joined:
    Jun 7, 2017
    Posts:
    372
    I think you're mostly on the right track. A scriptable object is mostly used as a container for information. So you would make a script like this:

    Code (CSharp):
    1. CreateAssetMenu]
    2. public class InventoryItem: ScriptableObject
    3. {
    4.     public string name;
    5.  
    6.     public Sprite iconSprite, smallIconSprite;
    7.  

    Once that script exists in your project, you can create (right click in your assets folder) the actual SO and enter the name etc. in the editor. You would create one SO for each kind of item. The item prefab, the object that will actually exist ingame, has a script with a field on it that references a SO of type "InventoryItem", it can then extract the name, the icon sprite etc. from it.
     
  3. Stardog

    Stardog

    Joined:
    Jun 28, 2010
    Posts:
    1,913
    You are correct about the ScriptableObject. It's an asset. The asset itself is the 'instance'. You make more instances just by duplicating it and renaming it.

    The alternative is to go into your database script and "new it" (instantiate) manually, e.g. 'ItemDB.DB.Add(new Item("Name", 234, 293))'. Instead, if it's an SO, you can just load them all into the list from a folder.

    Pickups could be their own thing, not related to the item. It can reference a SO, or use a database ID to decide which object it will add to the inventory. The SO could also contain info on what "world model" should show. So the pickup object isn't really the "item".
     
  4. TheJohnRudy

    TheJohnRudy

    Joined:
    Oct 14, 2019
    Posts:
    9
    Thank you for the answers. I do now get what SO's are but no idea how to actually create lists with them. I'll be looking into lists now and how to read them.

    Thanks again.