Search Unity

Inventory Help!

Discussion in 'General Discussion' started by JVGameDev, Mar 30, 2017.

  1. JVGameDev

    JVGameDev

    Joined:
    Oct 5, 2015
    Posts:
    137
    Hi! I come from Game Maker, and I kind of switched to Unity mid way through learning how to make an imventory. I was wondering in Unity how to do this? How is the data items stored, and how do you make the inventory "sortable"?
     
  2. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,694
    Hi and welcome to Unity!

    In Game Maker, a lot of this functionality is built in.

    Unity is more of a blank slate. You can write your own inventory system or use one off the Asset Store. There are some excellent paid choices, and some free choices like Inventory Master to get you started. Unity's Adventure Game Tutorial also has a section on Inventory.
     
    Last edited: Mar 30, 2017
  3. JVGameDev

    JVGameDev

    Joined:
    Oct 5, 2015
    Posts:
    137
    Damn, i didn't see that! Thanks! I've actually been using Unity for a while, it's just been a lot more working with engine and i haven't done a ton of coding.
     
  4. JVGameDev

    JVGameDev

    Joined:
    Oct 5, 2015
    Posts:
    137
    Actually, while i got you here, can you explain to me what null is? Not the reference error, but simply if a script checks to see if an object is null, then do something. I dont know what null really is.
     
  5. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    21,147
    It's basically a reference to nothing.

    https://msdn.microsoft.com/en-us/library/edakx9da.aspx
     
    TonyLi likes this.
  6. Master-Frog

    Master-Frog

    Joined:
    Jun 22, 2015
    Posts:
    2,302
    Hello, I too came from GameMaker, originally.

    You will need to learn C#, friend. GameMaker gives you tools for making games, whereas Unity gives you a lot less to start with.

    An inventory is really nothing more than a list of stuff that your dude has.

    The individual items can be defined some place else, as far as what they do, what they're called, etc. The inventory just keeps track of which items the player has.

    I would recommend creating a Dictionary, the keys can be item names (string) and the values can be your own user defined class Item.

    In Item you will have a text description, how much it sells for at the shop, how much you can buy it for at the shop, an ItemType enum to say KeyItem or Consumable or Equipment and then a link to an Effect or an EquipmentAttribute.

    Another fun way to do these sorts of things is to build them right in the editor. Dynamically add new pieces of equipment in the inspector.

    or each piece of gear can be it's own prefab component, if you can to be really crazy.

    it's all up to you, but it won't be as easy as gamemaker.
     
  7. Not_Sure

    Not_Sure

    Joined:
    Dec 13, 2011
    Posts:
    3,546
    I think you may need to spend some time in the learn section.

    Try doing the Tanks and the Roller Ball tutorials.

    Also, you're going to need to change your profile pic. While your support is welcome, there's rules about representing yourself with Unity stuff when you're not really affiliated with Unity. Someone could see your pic and mistake you for a representative.
     
  8. Taorcb

    Taorcb

    Joined:
    Mar 15, 2015
    Posts:
    39
    I'd second everybody else and say try something simpler, get the hang of it, then come back once you know more.

    As for me, my inventory system is a simple list of integers with an item database that I can search through when spawning AIs and switching clothing between male and female models. The UI script takes the contents of the list and grabs an item class that contains data like it's name, type, and some statistics (damage, description, etc). The Item class also has a reference to an asset so I can instantiate it. Works well when there's lots of characters with lots of separate inventories, but instance management gets pretty complicated pretty fast. It also doesn't lend itself well to drag-n-drop systems, but I haven't got one and I don't plan on making one.

    Your system will depend a lot on what you need, whether the inventory is only for the player or whether you're doing a Bethesda-esque system where literally every living being in the game has one (like me).

    Also sorry for necroposting. I was bored.
     
  9. DragonSAR2013

    DragonSAR2013

    Joined:
    Apr 26, 2013
    Posts:
    77
    You will need C# which is fairly easy language to learn.
    You can use something like this to sort in C#:
    ArrayList.Sort Method ()