Flexible INVENTORY SYSTEM in Unity with Events and Scriptable Objects

  Рет қаралды 81,074

BMo

BMo

Күн бұрын

Пікірлер: 85
@evanmiller2438
@evanmiller2438 8 ай бұрын
First of all, thank you BMo, this is an incredibly elegant and flexible system that you demonstrated. Thanks for the added delegate example, that helped me a heck of a lot to finally understand delegates (still not 100%). Posting this part for anyone else that might come across this tutorial and had similar trouble as I did understanding a few parts. I had a lot of trouble understanding the difference between the usage of the "inventory" list and the "itemDictionary" dictionary in the Inventory script. First of all, how you implement either of these entirely depends on how you will use the data from your inventory system later on. One thing that I got hung up on is that I thought these 2 variables were somehow linked together. They are not, they are independent. If you look in the inspector, you will only see the list. Even if you were to make the dictionary public, or serialize it, you wouldn't see it because Unity does not display dictionaries in the inspector. I believe BMo goes on in the next tutorial to use these two variables differently which is why he created both of them. I was so confused because to me personally I would have just looped through the dictionary keys instead of creating the list at all.
@dibaterman
@dibaterman 2 жыл бұрын
So for people as dumb as I am here is how Events are working in this very simple illustration provided in the video: Starts with > OnTriggerEnter > Looks for if the other has ICollectible if it does it fires off Collect > Collect fires off the Event inside of the collected item > Your Inventory was listening for this and fires off Add. What I don't see is a way to specific an inventory. So if you have npcs with their own inventory, this would technically give all the npcs inventory the same item regardless of who set off the event? I consider it a big deal for me if I can read the code well enough to understand that-that is likely the case, but I'll know for sure when I test it after finishing the video.
@sak5986
@sak5986 6 ай бұрын
First off, great tutorial, loved it. The only thing I'm wondering is how to implement a Use/remove functionallity with this. I've already tried event based, Raycast, buttons etc, but nothing has worked so far, so was just wondering. Anyway, great video BMo, hope to see even more in the future
@joshw5242
@joshw5242 2 жыл бұрын
I love your content! You're helping out with stuff that I have questions with and show it in a clear and concise way!
@mandamoon9149
@mandamoon9149 2 жыл бұрын
My happy inventory gets BIG when I see a new BMO video 😊
@ayeitskhi7549
@ayeitskhi7549 Жыл бұрын
Easy to follow along and packed with everything you need to get started another great video !
@BMoDev
@BMoDev Жыл бұрын
Thanks 👍
@phambaoha170
@phambaoha170 2 жыл бұрын
very intuitive and easy to understand
@KaanErayAKAY
@KaanErayAKAY 2 жыл бұрын
Great tutorial, great explanation. I hope your channel grows more.
@GalipCanKARAARSLAN
@GalipCanKARAARSLAN 7 ай бұрын
Just wonderfullll, love it and first time watching your videos, now gonna subscribe and open notifs...
@GalipCanKARAARSLAN
@GalipCanKARAARSLAN 7 ай бұрын
And please keep creating more videos/contents for game development
@psy_gamer
@psy_gamer 2 жыл бұрын
Very good video! The system is quite simple and convenient.
@Glori4n
@Glori4n 2 жыл бұрын
Thank you for the great insight!
@khaelus_dev
@khaelus_dev Жыл бұрын
Amazing tutorial. Thank you so much.
@Purgious
@Purgious 2 жыл бұрын
Doing God's work with your videos man!
@stefansigurdsson2146
@stefansigurdsson2146 2 жыл бұрын
Nice and clear tutorial!
@puntalic
@puntalic 2 жыл бұрын
Would by nice if the code alse accounted for a maximum amount of inventory space, like slots, or max stacks. Not hard to implement, but thought that part was missing. Maybe something for a follow up.
@frostymug3123
@frostymug3123 2 жыл бұрын
Best Unity tutorial series I've come across props!
@Stompin40
@Stompin40 2 жыл бұрын
Another banger
@kaisonlee71
@kaisonlee71 2 жыл бұрын
Nice video man!! Can you make a crafting system using Scriptable object for your next content?
@umapessoa6051
@umapessoa6051 2 жыл бұрын
Hi, thanks for the video, isnt easier to do a "public static event Action OnGemCollected" instead of a delegate with a parameter?
@BMoDev
@BMoDev 2 жыл бұрын
You can this was an excuse to explain delegates which i get asked about constantly
@umapessoa6051
@umapessoa6051 2 жыл бұрын
@@BMoDev oh alright, thanks !
@eileeng2492
@eileeng2492 2 жыл бұрын
Interesting topic Thank you
@darknside
@darknside 2 жыл бұрын
Nice content, thx man, i view from Russia
@farsquadfilmsltd.5997
@farsquadfilmsltd.5997 2 жыл бұрын
is there a way to do an inventory check? (i.e. you need a specific key to open a door.)
@molecular_master
@molecular_master 2 жыл бұрын
Ah man, why haven't you made this series earlier? This is a really clean and readable method compared to mine which is like spaghetti with meatballs :D
@sevazakharenko8176
@sevazakharenko8176 2 жыл бұрын
Great video, very helpful! One thing I am currently struggling with in designing my game is being able to save the game with a complex inventory system such as this. Would you be able to point me towards a tutorial you may have surrounding this topic? I have a solution to this that seems rather tedious, but it seems like there are very few data types you can save using the "System.Serializable" tag. But I imagine there must be some way of easily converting scriptable objects or something into simple data types and then saving those to a binary file. Either way, any help would be awesome, thank you!
@adygombos4469
@adygombos4469 2 жыл бұрын
At 11:00 I think Action does the same thing.
@anmaavr8315
@anmaavr8315 Жыл бұрын
I love your content! Thank you for the awesome video! Is it possible to reference the scene to the Scriptable object instead of the item icon?
@andrueanderson8637
@andrueanderson8637 2 жыл бұрын
Quick question about ICollectable + Gem as a class: Isn't "Gem" a game object? Making a MonoBehaviour called "Gem" seems to imply that the game object "is a" gem (inheritance) vs "has a" gem (composition). On the surface this seems to go against the notion of composition over inheritance. What am I missing?
@dibaterman
@dibaterman 2 жыл бұрын
Gem is attached to a gameObject thus making it a GameObject.. I think the disconnect here is that Gem is also and SO and Gem is also a list object. Similar data exists at the same time. In short the Gem on the screen, is not the Gem in the inventory, it's just a representation of data. The Gem class if I recall correctly is there to be picked up, so that technically is an ItemPickUp script that he named GemScript. Because it's a monobehavior you can do all kinds of things with it too, for example, since you are using SO you can set the items icon sprite and then on the pickup script tell the SpriteRenderer to use the icon as its sprite.
@PandoraBox06
@PandoraBox06 Жыл бұрын
For whoever want a mix between item stackable and not here is the thing i did to achieve that (not sure if its the best but it work) In ITEMDATA add the following bool after your other variable : public bool isStackable; in INVENTORY above everything in using add : using System.Linq; and in INVENTORY still change the method Add(ItemData itemData) to : public void Add(ItemSO itemData) { var thisItem = inventory.FirstOrDefault(x => x.itemData == itemData); if (thisItem != null && thisItem.itemData == itemData && thisItem.itemData.stackable) { thisItem.AddToStack(); OnInventoryChange?.Invoke(inventory); } else { InventoryItem newItem = new(itemData); inventory.Add(newItem); OnInventoryChange?.Invoke(inventory); } } and for Remove method : public void Remove(ItemSO itemData) { var thisItem = inventory.FirstOrDefault(x => x.itemData == itemData); if (thisItem != null && thisItem.itemData == itemData) { thisItem.RemoveFromStack(); if(thisItem.stackSize == 0) { inventory.Remove(thisItem); } OnInventoryChange?.Invoke(inventory); } }
@suicune2001
@suicune2001 2 жыл бұрын
Thanks! This was awesome. :)
@export_dev9164
@export_dev9164 2 жыл бұрын
Wouldnt it be better to have a general collectable pickup event so you wouldnt have to subscribe to the pickup event of every single collectable item you have in your game?
@AsaFalyRayyan
@AsaFalyRayyan 4 ай бұрын
Great tutorial! But what if I have more than 1000 collectible items(gem, gold, silver, so on), do I have to create all script for each item called gem.cs gold.cs silver.cs, or is there a better way?
@hipppiejesus4567
@hipppiejesus4567 2 жыл бұрын
when did he script blueGemData ?
@disruptive_innovator
@disruptive_innovator 2 жыл бұрын
Thanks for the tutorial. Why use a List and a Dictionary at the same time? Maybe just use the Dictionary?
@BMoDev
@BMoDev 2 жыл бұрын
The List is useful for things like ordering/sorting your inventory, but again everything can be adapted to what you need for your situation. If it doesn't offer you any utility, scrap it.
@disruptive_innovator
@disruptive_innovator 2 жыл бұрын
@@BMoDev Makes sense. Thanks.
@Xu0mi_
@Xu0mi_ 11 ай бұрын
Hi! And how to make gui inventory in which the Icon and the Amount of the item will be recorded?
@DarkkneZPanda
@DarkkneZPanda Жыл бұрын
it seems subscribing to the events for the audio and text scripts from the previous video has errors because its a different delegate. Any way to fix this?
@samserious5483
@samserious5483 2 жыл бұрын
Very clean, thanx
@Corummo
@Corummo Жыл бұрын
With this kind of approach, every single collectible item has a separate class with an inner event to subscribe to. So if I add a new item to my game, I have to create a separate class with its own new event to subscribe. And what if my game has to manage 1000 collectibles? This method doesn't take any advantage from the ScriptableObject real purpose, i.e. decoupling data from the source code. The ideal implementation would be limited just to the creation of a new ScriptableObject, leaving the core code untouched. That's the purpose of ScriptableObjects, as clearly demonstrated by a very old Brackey's video on the subject.
@TimelordSnowy
@TimelordSnowy 2 жыл бұрын
how to do this without events? Im not picking up items. But this is like exactly how I want my inv to function. But I keep getting a nullreference when i try to add items
@bidjo666
@bidjo666 2 жыл бұрын
Hello, what about saves? How to save Scriptable Objects in a build.
@novachi09
@novachi09 2 жыл бұрын
Don’t you think it would be better to just stick to a dictionary and use the List of values instead of the inventory list? It would make it a single source of truth for the whole inventory. I might be wrong tho since I’m a beginner when it comes to C# and Unity but for me it would make sense.
@mr.pillow
@mr.pillow 2 жыл бұрын
can u do 2-player controls?
@employerslave
@employerslave Жыл бұрын
for example I have a key and I use it on the door how can I delete it from inventory?
@Gears2Game
@Gears2Game Жыл бұрын
Get reference to the Inventory and on your on use key logic, call the Remove(itemdata) - your key itemData.
@PrototypeMarl
@PrototypeMarl 2 жыл бұрын
Either this doesn't work with Unity 2021.3.8f1 or I'm just doing something wrong
@keithwilliams1921
@keithwilliams1921 Жыл бұрын
it worked for me
@butchinator1988
@butchinator1988 Жыл бұрын
Am I being an idiot? Where are the items being stored? Im not reaching AddNewItem as the inventory is already populated but I cant physically see the list. Is it stored somewhere in Unitys memory?
@blinken77
@blinken77 2 жыл бұрын
Hi! Great tutorial but i am trying to make it so that if you try to pick up two swords of the same type you can only pick up one. Can you help me with this if it is possible?
@heribertosalais4678
@heribertosalais4678 2 жыл бұрын
What is the meaning of the operator "?." on 0:45 in the line "OnGemCollected?.Invoke();" ?
@Worrior314
@Worrior314 2 жыл бұрын
It is the short hand writing for: if (OnGemCollected != null) { OnGemCollected.Invoke(); } if he doesn’t check for null and nothing is subscribed to the OnGemCollected event, it would throw an error message.
@mysterycube9891
@mysterycube9891 2 жыл бұрын
hey man thank you for helping beginners. I have a question how to separate 2 game object with same script? i have 2 object and both of them have enemy script and on Death method i Instantiate an effect with event Action but when i kill one of them the effect plays for both of them even though one of them is still alive.
@firebiscuitgaming7624
@firebiscuitgaming7624 2 жыл бұрын
hard to say without looking at your code but my intuition is the bug might be in the code that decides which enemy to target for the death event.
@SeverskiyS
@SeverskiyS 2 жыл бұрын
maybe you use static events?
@darkman237
@darkman237 2 жыл бұрын
What if you wanted separate types of items like a weapon, an armor, something consumable like a potion?
@Community-Compute
@Community-Compute 2 жыл бұрын
Add an enum to the ItemData Scriptable Object that stores an item type. That's a simple way.
@chritsfootballs
@chritsfootballs 2 жыл бұрын
You can also make an abstract itemData class then make different scriptable objects with different fields
@darkman237
@darkman237 2 жыл бұрын
@@chritsfootballs That's a cool idea! Could you give an example?
@chritsfootballs
@chritsfootballs 2 жыл бұрын
@@darkman237 coding with unity has a video on it in his part one. int eh scriptable object inventory System
@darkman237
@darkman237 2 жыл бұрын
@@chritsfootballs Thanks!
@godzillakingkongvenom
@godzillakingkongvenom 2 жыл бұрын
🔥🔥🔥🥦🎮
@anonym78654
@anonym78654 Жыл бұрын
Is it Working on 3d game
@officiallambs
@officiallambs 2 жыл бұрын
Epic!
@heyreefes
@heyreefes 2 жыл бұрын
Naisu
@dkordy
@dkordy Жыл бұрын
Unbelievable, but all you developers. Everyone, literally. Something always goes wrong in the tutorial, and I struggle with that something for days afterwards. For example, here in this Inventory tutorial everything is perfect and you explained everything perfectly, but in the end when I created Inventory, and in Update() succeeded on some key when I press to hide it and display it Inventory - when I pick up the Item, of course it is not displayed in Inventory because for example the Inventory -panel is inactive at the time. So, in order for it to be displayed when I pick up an Item, I have to have the Inventory Panel Active (visible) all the time, otherwise it won't process - Slot wont be Upadated. Do you understand me? No Updates on the Inventory slot when the Inventory Panel is not active. And now I have to waste days and days until I find the answer to how to do it. You could have just mentioned - If you don't want the Inventory panel to be always visible, then you should do this and that in order for the slot to be updated. And of course you didn't say that, you left it out, and that's what everyone, literally everyone does, always leaves something out. Not everyone wants their inventory panel to be visible all the time... How i now to resolve that problem? Can you tell me?
@dkordy
@dkordy Жыл бұрын
PLEASE!!!!
@verenabecker2724
@verenabecker2724 Жыл бұрын
This is one of the most entitled posts I've seen in a long time. Dude, there are a billion different small issues that will crop up for different people implementing this in different circumstances and maybe using different versions of Unity. It makes you seem incredibly ungrateful if you're this cranky about a free tutorial not catering to your exact needs. No one here owes you their time and expertise.
@dkordy
@dkordy 2 ай бұрын
@@verenabecker2724 So, did I ask you for something? After all, I didn't demand anything from anyone, I just asked for help. If it's none of your business, why bother answering anything? Unless you're being paid to shove yourself where you don't belong? I'm not being ungrateful or grumpy, I'm just stating my observation of the tutorial. And I exposed that to whoever made the tutorial. But I'm sure my post doesn't concern you. No one asked for your opinion on my post, so if you don't want to help, ignore it. Or are you crawling up the "professor's" a** to score some points? I don't understand, why are you stuffing yourself when no one asked you anything?
@JAKEAVALON-rg8xm
@JAKEAVALON-rg8xm 2 ай бұрын
I just used easy method GameObject flase and true😂
@urpwnned
@urpwnned Жыл бұрын
i have 0 clue what the hell "item" is referencing
@SeverskiyS
@SeverskiyS 2 жыл бұрын
isnt static events a horrible idea?
@Reaxgrim
@Reaxgrim 2 жыл бұрын
nm fixed it :D lol
@mike_b10
@mike_b10 2 жыл бұрын
🙏
@fatihemirhangungor8297
@fatihemirhangungor8297 2 жыл бұрын
What's your equipment ? Like keyboard ?
@BMoDev
@BMoDev 2 жыл бұрын
I have a custom mechanical keyboard, but brown switches
@form2105
@form2105 2 жыл бұрын
I sub pog
Simple Inventory UI in Unity With Grid Layouts
18:59
BMo
Рет қаралды 23 М.
The Power of Scriptable Objects as Middle-Men
17:41
samyam
Рет қаралды 129 М.
Trick-or-Treating in a Rush. Part 2
00:37
Daniel LaBelle
Рет қаралды 46 МЛН
Twin Telepathy Challenge!
00:23
Stokes Twins
Рет қаралды 59 МЛН
КОГДА К БАТЕ ПРИШЕЛ ДРУГ😂#shorts
00:59
BATEK_OFFICIAL
Рет қаралды 8 МЛН
A Great Way To Setup POWERUPS In Your Unity Game
13:43
Be CAREFUL with Scriptable Objects!
8:27
Code Monkey
Рет қаралды 84 М.
Flexible LOOT SYSTEM in Unity with Random Drop Rates
13:24
I Made the Same Game in 8 Engines
12:34
Emeral
Рет қаралды 4,2 МЛН
20 Advanced Coding Tips For Big Unity Projects
22:23
Tesseract
Рет қаралды 199 М.
Unity INVENTORY: A Definitive Tutorial
35:21
Coco Code
Рет қаралды 120 М.
Giving Personality to Procedural Animations using Math
15:30
t3ssel8r
Рет қаралды 2,6 МЛН
Trick-or-Treating in a Rush. Part 2
00:37
Daniel LaBelle
Рет қаралды 46 МЛН