Simple Inventory UI in Unity With Grid Layouts

Поділитися
Вставка
  • Опубліковано 3 лип 2024
  • ➤Previous Inventory System Tutorial (Watch First): • Flexible INVENTORY SYS...
    Creating an inventory isn't so hard, but displaying it in a nicely presented way can be... but its also a lot of fun.
    There are so many UI options for an inventory that can all function differently that its really hard to make a tutorial for it, but I figure most people atleast just need to be able to display inventory slots inside some larger container.
    Using Layout groups (grid, vertical, horizontal) can give you the grid your looking for in Unity.
    By the end of this unity tutorial you'll be in a good place to expand your Inventory UI in any direction you want.
    ✨Want to support the channel?
    Buy me a coffee ☕: ko-fi.com/bmoli
    ➤SUBSCRIBE to inflate my ego with a bigger number 💖
    ➤LIKE the video if you enjoyed, it really helps the channel!
    ➤Join our DISCORD SERVER and become the worlds first trillionaire: / discord
    Thanks for watching!
    #unity #tutorial #inventory #bmo

КОМЕНТАРІ • 55

  • @ericwd136
    @ericwd136 2 роки тому +2

    Wow, I can't believe this doesn't have more views! This is the shiny visual reward for all the coding in the other parts of the series! Great tutorial, my brain is struggling a little will the abstractions and excessive use of the word "inventory", but I think I get it. I needed to invoke the OnInventoryChange change event in the Start method of my Inventory class to get the empty slots to draw before picking up any items. In addition to just making something functional, I feel like this series helped me understand events and scriptable objects too. Thank you!

  • @mandamoon9149
    @mandamoon9149 2 роки тому +2

    Love the layout suggestions, the easy way you explain ideas makes all the difference! Always look forward to your posts 👍

  • @revmatch6r
    @revmatch6r 2 роки тому +6

    This was exactly what I needed to put the finals pieces of this together. Some key parts I was totally not understanding

  • @tarot1234567
    @tarot1234567 2 роки тому +1

    Absolutely amazingly clear, concise, and precise presentation on how to establish an inventory system. I wish I had seen this a year ago for my own project. Thank you!

  • @rodmileski
    @rodmileski 2 роки тому +11

    Feels like your channel needs more visibility brother. Nice explanation, straight to the point and with high quality.

  • @deadbroadcastpc
    @deadbroadcastpc 2 роки тому +3

    Some core fundamentals here man. Enjoying the recent content brother, always well done

  • @eileeng2492
    @eileeng2492 2 роки тому +2

    Excellent pull together of these elements.
    Good job

  • @Stompin40
    @Stompin40 2 роки тому +4

    Great video, thank you!

  • @waffel6378
    @waffel6378 2 роки тому +3

    Thank you man!

  • @rumblenin
    @rumblenin 2 роки тому +1

    Really like the way to make your videos. Keep up the good work!

  • @suicune2001
    @suicune2001 2 роки тому +3

    Thanks!

  • @savannahmtanner
    @savannahmtanner Рік тому

    Hello! Awesome video, I have been watching in order the last few for a project. Thank you for the great content.

    • @BMoDev
      @BMoDev  Рік тому

      If you share your scripts i can take a look

  • @tierzznick6449
    @tierzznick6449 2 роки тому +5

    Amazing work and on such a beginner friendly level compared to other inventory tutorials and guides out there! But could you go over Item drag and swap?

  • @mattallenclosedforum9505
    @mattallenclosedforum9505 2 роки тому +8

    Do you have your code anyway avaliable for download on a github or g drive so we can compare (when we go wrong) without having to pause the videos?
    Thanks

  • @carlogiovanni
    @carlogiovanni Рік тому

    Thanks for this, I found you go quite quickly coding into the editor but suppose I need to get better! :)

  • @matteocordioli7066
    @matteocordioli7066 2 роки тому +3

    Well done! Can u explain how the canvas work with different screen ratio and how to set it up to make it scales right with all the ratio?

  • @addisonjacoby
    @addisonjacoby Рік тому +4

    How big would an inventory need to be before you looked at different ways of drawing the slots? And do you have any suggestions on where to look into a more efficient way? I was planning on having an inventory open/close and only updating when the inventory has changed.

  • @Katubug
    @Katubug Рік тому +2

    Hi! I've been following your tutorials and they've been really helpful! I appreciate that you explain why you make the choices you do, and what the drawbacks might be. I do have one question though: do you have a recommended resource/video to learn a different way to update the inventory instead of destroying and rebuilding? Thanks!

  • @MysteriousGamesOfficial
    @MysteriousGamesOfficial Рік тому +1

    How would I go about making an "equip item" system with this inventory?

  • @Sam4Progress
    @Sam4Progress 3 місяці тому

    I didn't know Grids, and grid components were literally default things Unity offered. I've been dreading making a Grid script that could be flexible for my needs... I might still need to do that but at least I know I have options!

  • @danielrosenberg7174
    @danielrosenberg7174 Рік тому +1

    You can't use this system to make max stack right. like in Minecraft for example. having 2 stacks of cobblestones. as the dictionary key is the item you cant do like if I have 64 off 1 item it's going to spill over to the next inventory item in the list. or am I missing something? I really appreciate any help you can provide.

  • @agonzio2107
    @agonzio2107 2 роки тому +1

    Great tutorial, everything was easy to follow and modify but one thing I don't get is: How can I implement the Remove function? been trying with input and buttons but I just can get the "how".

  • @ttv_dark_scorpion
    @ttv_dark_scorpion Рік тому

    How would I make more than 1 item show in the inventory because when I did it the gem worked fine but i dont know how to make any other item show. Would I have to copy the code for the gem and change some names for it to works on any other item?

  • @L2George
    @L2George Рік тому

    How can i add more items?

  • @ThePoePoee
    @ThePoePoee 7 місяців тому

    I made it so the inventory is opened when player presses down the "I" key but whenever I go to pick up an item with the inventory closed, the inventory doesn't update. When I walk over the item with the inventory open, the inventory does update tho.

  • @inkofthedragon
    @inkofthedragon 2 роки тому +4

    Could you do a video showing the using of items? Like a helmet, that shows up on the player that can also reappear in ui when unequipped. And the consumption of items like a healing potion? Thanks!

    • @RudolfJvVuuren
      @RudolfJvVuuren Рік тому +1

      Yes totally. I've managed to get my inventory working (in that it starts generating the icons in the inventory), but I am struggling now to remove items (icons) from the inventory when it needs to. I've set my code to "destroy(the icon prevab);" but for some reason the icon doesn't go away from the inventory :(

    • @lawrencemiller2642
      @lawrencemiller2642 Рік тому

      @@RudolfJvVuuren did you figure it out?

  • @TheMadGamer27
    @TheMadGamer27 2 роки тому +2

    That was very helpful but how do you actually remove an item from the inventory?

    • @RudolfJvVuuren
      @RudolfJvVuuren Рік тому

      Yes, that's what I also want to know now lol

  • @herzoghydra5353
    @herzoghydra5353 Рік тому

    when I pick up an item the ifrst time, the icon name and stacksize wont pop up in my UI. I copied everything what he did. What should I do?

  • @TransGuyShane
    @TransGuyShane 2 роки тому +5

    Will this save from scene to scene ?

    • @322ss
      @322ss 2 роки тому

      Nothing stays from scene to scene in Unity... unless it is in a scene or gameobject that doesn't get destroyed when transitioning to a new scene. Another way is to use non-MonoBehaviour vanilla C# classes that live only in memory, and keep your inventory data there, and rebuild/populate the UI after loading a new scene. Look into topic of serialization/deserialization (to files) if you want to save your inventory items permanently to disk and then load them back at later time.

    • @TransGuyShane
      @TransGuyShane 2 роки тому +1

      @@322ss thank you :)

  • @herzoghydra5353
    @herzoghydra5353 Рік тому

    And how to add more different
    Items?

  • @blinken77
    @blinken77 Рік тому

    Im not catching on? When did we make the inventory item script? Edit: It was another lol

  • @thecommentator9043
    @thecommentator9043 Рік тому

    I hope that i will be as good as u :o maybe one day i will :D

  • @KrazyIndeed
    @KrazyIndeed Рік тому

    How can I make an image of a 3D object? I have an inventory GUI with 4 slots.. If the player picks up a knife in the game, how do I get an image of that knife to display in my inventory?? I assume I have to get an image of it, but how do I do that? I can seriously only think of getting a screenshot and then editing it in something. That sounds TEDIOUS for multiple items and images..

  • @davidbzrz
    @davidbzrz Рік тому

    Hello, thanks for this nice tutorial,first. I’m learning a lot. When I play the scene my inventory redraw another new inventory just down the old one after getting the first item, and when I go tho pickup the next item Unity breaks:( Somebody know what could be happening? Thanks a lot.

    • @davidbzrz
      @davidbzrz Рік тому

      Finally fixed! Thaaaaaanks

    • @iangraham6730
      @iangraham6730 10 місяців тому +1

      @@davidbzrz it might be helpful for others, who could be in the same situation, to explain how you fixed it ;-)

    • @Eqqs
      @Eqqs 13 днів тому

      @@davidbzrz I have the same issue, how did you fix it?

  • @dibaterman
    @dibaterman Рік тому +3

    Alright, this aint good I think. On the other video I was able to expand on the idea - this one feels like I got knee capped. I think I'm getting PTSD for multipart tutorials cause I keep getting the rug pulled out, thankfully this was two parts.
    I posted on the previous one a method to have mutliple inventories using the system BMo made. The system from the previous video is very simple and a great structure for evolving new ideas from. This one is riddled with just too many pitfalls:
    Destroying the whole inventory and instantiating it when a new item is added, the problem isn't the efficiency for me it's how do you even setup a modular way to adjust the max inventory? Its baseline really bad to just put in an integer for something like that. I tried the obvious of making an int but Unity doesn't like that, so I tried a getter setter, but his system doesn't like that down the road when you are instantiating the entire thing again. So I tried using a lamda at cache no go. Then I said screw it let's make a Start for it and set things up there.
    It worked fine but because it is happening at Start the first item is the only item it keeps populating to the inventory rather than what is actually in the inventory. This has me totally at a loss XD. Anyway, broke the whole damn thing in the end even the part that was working from the last video, feels bad but moving on - thanks for the attempt though man.

    • @danielrosenberg7174
      @danielrosenberg7174 Рік тому

      did you find a better solution?

    • @dibaterman
      @dibaterman Рік тому +1

      @@danielrosenberg7174 Mhm,
      Inventory is complex, I'll be short and clear about this:
      Pre: Assuming you have the item data setup already.
      1. Create a class for slots, give it all the data you want the slot to have. (Image, Stack Count, etc) This slot will also have methods to handle interactions with the slot. (Clear Slot, Populate Slot, Check Slot, Swap Slots, etc). I also had an item type which I could refer to if I wanted a specific slot to only allow a specific type of item. (Equipment).
      2. Make a monobehavior for the Inventory and put a list of the type of your class for slots. I'd give this list a max size so as to allocate memory for better performance. Put methods in that to populate the list. Inventory is very generalized; it's however you need it to be but generally I found the methods I used were: AddSlot, RemoveSlot, TransferSlot.
      All in all, it's not impossible but it certainly is a complex thing to work out.
      After this I made 2 visualization monobehavior classes, one for the inventory the other for the slot.

    • @danielrosenberg7174
      @danielrosenberg7174 Рік тому +1

      @@dibaterman this is great. thanks for the long answer. to add to what you're saying. when I add an item in to this. how do I check if a slot already contains that item and is not full?

    • @Katubug
      @Katubug Рік тому

      @@dibaterman Thank you for this! Would you be willing to share a code example? Or was there a video you watched to get this working? I am trying to follow your instructions, but I feel like I might be too beginner just to go off of the description.

    • @dibaterman
      @dibaterman Рік тому +2

      @@danielrosenberg7174 Sorry didn't see this, you probably have an answer already, but if not: First understand that your inventory is a List/Dictionary/Array (whatever you chose). Second understand that you don't need to search the list since you've visualized it as a UI.
      So what you want is something that you can attach to a hidden slot. The slot doesn't have to be hidden though, it could be a slot that follows the mouse when you have the inventory open. The idea is you click the visualized slot, and the slot just needs a button on it that triggers when clicked. (You can also create another UI element that pops up when clicked and add context there). Then just copy the data from the slot to the mouse slot/hidden slot.
      Then click the slot you want to put things on, and have a onclick check/condition that if your hidden slot is populated then it will either add if the current (clicked) slot is empty or transfer.
      Transfer is simple, just make a data type to hold transfer data for that slot. So within the transfer method initialize a new slot for data, store the old data in the new slot, then put the slots current data into the hidden/mouse slot data and finally put the new slots data(your old hidden/mouse data) into the current slot.

  • @bobli75
    @bobli75 Рік тому

    My problem was that slots item didn't get .enabled = true.
    So nothing appeared in my inventory.
    I solved by looking 11:41. My for loop was problematic.
    I wrote (int i = 0; i > inventorySlots.Capacity; i++). The > was on the wrong side.
    Solution : for (int i = 0; i < inventory.Count; i++)
    with the < on the good side.
    Best video on the topic btw ;)

    • @iangraham6730
      @iangraham6730 10 місяців тому +1

      You probably know by now, but to avoid little mistakes like that, in VS you can just type 'for' then double 'TAB' to auto create the loop, then just add your variables.

  • @TheRyanSmee
    @TheRyanSmee 2 роки тому

    Great video - Thank you!