Here's a great simple but also very robust Inventory System! You can apply this to Enemies and make them drop items on Death! Play 7 Awesome Games (Action, Strategy, Management) and Help Support the Channel! Get the Game Bundle 67% off unitycodemonkey.com/gameBundle.php
Simple yes, but not robust. You need more abstraction for robust code. For stable and flexible systems try to use "solid principles". These are amazing.
i dont mean to be off topic but does anybody know of a method to get back into an instagram account?? I was stupid lost the login password. I would love any tips you can give me!
The fact that this is considered "simple" inventory system is really just a testament to how deceptively tricky these systems really are. Great tutorial though, really does help a lot once you hit the point of understanding a lot of the fundamentals of the Unity engine.
1:32 Item List 3:50 UI visuals 5:20 UI script 7:40 Proper visuals on each item 9:12 Pickup item world 11:55 Lights(skipped) 12:20 Pick up item 13:30 Update inventory 15:00 Spawn items in world 16:50 Stacking items 18:20 Display amount 20:40 Use and drop items 23:00 Improved Drop
Great video! Learned a lot more about Unity compared to the others I have followed. Though, due to a mistake I had to restart this from scratch. The cloning of the 'itemSlotContainer', and 'itemSlotTemplate' wasn't an issue before; now it's an obstacle since the cloning are now stacking on top of each other instead of a grid-like structure. If anyone has any pointers to how to fix this would be greatly appreciated. Thank you for your time. SOLVED: Make sure you put "int x = 0;", "int y = 0;", "Float itemSlotCellsize;" BEFORE the foreach. As all programmers know, lethargy is a pain, and brain fog is bound to happen. Keep on, keepin on!
Like a lot of people in watching this video, I've been trying to knock this out, and after a solid week of trying, failing, and starting over, I finally managed to make it to the credits of a video about this. While there are still a mountainous number of issues left to work out, you sire have earned another shout out in my dev log. Hope you tune in to see it!
@CodeMonkeyUnity Thanks for watching! It really means a lot to me. I just posted a new entry discussing all of this inventory stuff yesterday, and you're featured in it! Give it a watch when you can 😁
I was going through some other tutorials where the video creators just expected you to have magically watched the other 100 or so videos in their channel, and didn't explain anything of what they were doing Seeing you reply to people even in this video of 3 years ago (and also still keeping the project public) makes me truly admire you and your work, a glimpse of hope in this hellhole where people literally just want to learn. Thank you for doing what you do to this day man.
5:56 I would recommend calling inventory = new Inventory(); uiInventory.SetInventory(inventory); in Start() instead of Awake() - When called in Awake it can break because of the dependencies in UI_Inventory and ItemAssets, which both are also called on Awake and cause mistiming.
I watched this video so many times (in parts of the video), I just got your "How to fix NullReferenceException in C#" video as a YT ad on this video. This tutorial is called "simple" but it is the most densely edited, long tutorial, covering a lot. I have underestimated your patience and experience level :3
For those that tries to do this tutorial and faces the exception about nulled references from inventory, this is because they use the Awake() function. Because of this some scripts are not yet initialized and therefor you get the errors. Solution is to either change Awake() to Start() and hope they get executed in the right order, or go to script execution order in the Project settings and set the order on how it is supposed to work. I've seen these issues in alot of tutorials where the Awake function is used to get the editor in unity updated quickly.
It took a bit of tweaking to get this to work in a 3D space, but this tutorial helped me understand the basic logic behind how an inventory works in a game. Great tutorial! Looking forward to learning more from you.
This took me a long time to figure out, but for those using more recent versions of TMP, it seems they refactored it to only need TextMeshPro without the UGUI and Canvas Renderer stuff, so if you're getting null reference exceptions, that could be one reason. Another thing that took way to long to figure out is that script execution order REALLY matters to this system and I wound up placing the Item Assets and UI scripts BEFORE default time in order to get it to run and force their Awake methods to call.
i might've the same problem "CS0649 player.uiInventory is never assigned to" even though I assigned as at 5:48. can you elaborate more how you fix it. edit: fixed, Edit - Project Settings - Script Execution Order, then put UI_Inventory before Player so that the script exist when Player asked for it
i know this video is old but for anyone wondering on how to limt items stacking, i made for the inventory script to add ........ if (inventoryItem.itemType == item.itemType && inventoryItem.amount != item.maxAmount) and for item script to add public int maxAmount (p.s. im very new to codeing,so tell me if im wrong so i can improve )
Refreshing inventory should be done in a better way, this way is really taking on the performance. In case you get more than 20 items you gonna notice big spikes when inventory changes. Other than that, very cool
Hey man, I'm kind of a beginner, and I was gonna implement an inventory system with the logic used in this, but I just cant seem to understand how the Item can simply be passed in to the UseItem function. Does it not need a reference or the enum to be set to that particular item to tell which item the player is using, or does it actually know that from a particular logic?
Your comment is monthes old so idk if you still don’t know, but basically the UseItem function is taking in arguments (the extra stuff in the parantheses next to “UseItem”) which, in simple terms are basically bits of information necessary for the function to run. They also serve as a reference to whatever data is sent into that function, so by calling the function and sending in the item, you are effectively creating a reference to said item
i wish you would explain why you are doing what you are doing and not only state what you are doing... brackys for example explains why he chooses to do what he is doing and dont just state what he does.. for example.. if you made enum or a certain function or constructor you need to explain why did you choose this method and how it functions in the game... this is what makes a teacher a great teacher. thanks.
I assume you know the basics of Unity and C# and with that you should be able to follow everything. What part couldnt you follow? If I explain what is a function and what is a variable in every video then all my videos would be 2 hours long.
It's not my place to say this, but I'll say it anyway. That is not how FREE tutorials work. The way he teaches is different than Brackeys and some people like that, others don't. I don't see where CM is getting paid to do this or satisfy anyone, so... Please think carefully before comparing people and choosing words like "you need to do such and such." Thanks.
took me some days but finally finished the tutorial, after countless stops to "do my stuff", which means, doing unrelated things like the start of a hotbar system and... decompiling a game to modify it too, i guess
I like your process of fast forwarding the video when there's tedious bits, but I think this is terrible for anyone new that wants to actually learn what you're doing :(
This is an okay inventory system, to make it more scalable, I switched to using ScriptableObjects for the items allowing me to store the item details in that S.O., ie name/sprite/etc. I also setup the InventoryUI to be able to dynamically create slots as needed. that way if I want different sized inventories or items that add more slots i can create logic to handle it
Assets\Scripts\ItemWorld.cs(28,38): error CS1061: 'Item' does not contain a definition for 'GetSprite' and no accessible extension method 'GetSprite' accepting a first argument of type 'Item' could be found (are you missing a using directive or an assembly reference?) Does anyone know how to repair this?
To those that are stuck on the useitem (timestamp starting at 20:40) portion (where you left-click on a non-stackable item and it doesn't remove from your inventory) - I did away with the "if(item.IsStackable())" condition within the "RemoveItem" method and now my inventory is working as expected (decrementing an item in the inventory down both for stackable and non-stackable items). What I found is that the IsStackable condition was the only one being allowed to decrement the count or amount on the item and anything else was not being included in the logic. I reviewed that section and other sections of this video at least 5+ times and confirmed my code was a 1:1 match to the code content. So either something changed in Unity (this video is 3+ years old, so wouldn't surprise me), something is bizarrely different in my project (which is weird because I saw others had a similar problem based on the comments), or the logic being provided in the video is flawed and was updated without an update to the video. I even created a shit-ton of debug.log statements (which seems to be the only feedback that was given by CodeMonkey in the comments - aside from ghosting others) and I got a big nothing out of doing that. I'm glad that I finally got my inventory to work, but man was it a pain in the ass to get that last bit working. Quick Edit: I discovered that dropping items becomes an issue for non-stackable items if you have more than one of that same item in the inventory (makes sense since it's just decrementing regardless of it being stackable or non-stackable) - To avoid further headache, I just made two separate methods (one to remove items and one to drop them) - the drop method is just the original code from the video for remove item (since the drop item was the only function that worked for me previously) and then have the remove item (code below) for decrementing the item when using it. Here's the code section for the Inventory class in case anyone wanted to try this solution in their project: ------------------------------------------------------------------------------------------------------------------------------------------------------------ public void RemoveItem(Item item) { Item itemInInventory = null; foreach (Item inventoryItem in itemList) { if (inventoryItem.itemType == item.itemType) { inventoryItem.amount -= item.amount; itemInInventory = inventoryItem; } } if (itemInInventory != null && itemInInventory.amount
From what you mentioned there's nothing specific to any Unity version, C# is still exactly the same C#, it's just logic, completely separate from Unity versions. The only possible feedback I can give you is indeed add tons of Debug.Log(); to see what your code is doing. Code is deterministic, if you write the exact same code you will get the exact same result so you clearly have something different, I can't magically tell you what. Instead of looking in the video you can download the project files and compare directly with your own
@@CodeMonkeyUnity First of all, I have to say thank you so much for all of your hard work with your tutorials. They have helped so much in understanding programming and unity in general and I genuinely feel that I would not have progressed even half as far without them. I have even purchased your Builder/defense course as well as visual scripting courses which I highly recommend to anyone wanting to learn! (They're very helpful! and fun with a nice pace that isn't dull at all imo) That being said..... This tutorial along with the drag/drop and Equipment tutorial are a pain, They just don't work, whether or not it's errors because of script execution order (using awake to get references along with alot of recttransform finding, just is not good practice for a system that needs so many references. I get that you want to be a purist and do everything through code, but I have to say that while I limit my use of the inspector...I have NEVER (maybe I'm lucky? dunno) had a problem with script execution order when I just drag and drop the needed references and make a prefab. I did download the project files from your (what I considered to be final version) equipment tutorial and there were some extras like "GetInventorySlotWithItem(item).RemoveItem();" which maybe could just be for the equipment, but it says for all inventory slots which is not included here, but being exactly as it is in this tutorial, dropping items works fine, but using them does not remove the last one from the inventory and you can use it indefinitely. side note: I get that this is supposed to be a "simple" inventory system that you state could be expanded upon, but this is a really poor way to implement inventory. Items SHOULD be scriptable objects where we could just add a sprite etc to represent the visuals. Who in their right mind would want to do this " in one class have to add public Sprite oneHandedswordSprite; , and in another class case ItemType.OneHandedWeapon: return ItemAssets.Instance.oneHandedswordSprite;" for EVERY single item in the game (not to mention having to add ACTUAL functionality like effect, stat bonuses, Set bonuses etc)!?! Sure, this could if you only had a handful of items in the game, but if you only had a handful of items why bother with this over complicated approach? creating an elaborate inventory system that is only manageable on a micro level is is bad game design and while most players want depth to their games, this isn't depth...this is the illusion of depth. Like claiming a game has rpg mechanics because every time a player levels up they do +1 damage. Most people would just rather not have a shallow system vs a real one. This system doesn't provide a realistic way to build further upon (unless you're a masochist), so it's just not worth using. I'm sorry for the rant, and I love your channel and everything you do for game developers, but this (in my opinion) should be remade or removed entirely) This is honestly the only video series from you that made me think "why is he teaching how to dig a miles long trench...with a plastic spork!?".
Is there any chance you could remake this with your newer code? I tried to convert this to the drag-drop armor equip and it's completely different. Thanks!
If anyone has problems with the clicks registering outside the visual box in the inventory: Make sure the Rect Transform of all the objects in the ItemSlotTemplate are inside the actual box. My text showing the amount was set to 200 width and I couldnt figure out why the clicks registered so far to the right of the icon.
There is always a lot of research that goes into making a video. What you see in the recording is after I've already written and rewritten everything 2-3 times. That's why I always tell people that they're not expected to follow the tutorial in realtime because even with all my knowledge I definitely don't build these systems the first time in just 20 mins. And yup I google things all the time. For simple things like this inventory system, which I've probably written 20 inventory systems in my decade of making games, for this I don't need to google much but for more complex topics yup all the time.
@@CodeMonkeyUnity thanks for the reply! That’s reassuring to me as a beginner that even the pros need to Google a bit. I’m extremely reliant on chatGPT in understanding the concepts used which makes me feel bad. But I ask it to explain the process step by step to understand exactly what’s going on so I can hopefully some day become less reliant on it🙂. Thanks again for working hard to produce amazing quality tutorials for us less fortunate enough to afford a college education ❤️
I've implemented a drop item system in my own game, but the "spawn" of the items, I made without rigid body, and rather with a lerp (and coroutine). I've noticed your approach with add force, and I find it way cleaner/simpler and probably even safer. The issue I ran into on the other hand is that my Item seems to slide to infinity after spawning. I wonder why is that. Are you using some kind of physics material on your ground? If I add angular drag to my object it stops correctly, but otherwise can't seem to get it work. Cheers and keep up the awesome tutorials! (P.S. It might be a little fast paced for beginners, but I can tell you that as an advanced Unity developer, I can follow along nicely)
No need for any special material, just set the Linear Drag to more than 0 and it will stop. If performance is an issue you can either do the drop animation through code moving the transform or remove the Rigidbody once its stopped.
@@CodeMonkeyUnity Yea, I did fix it eventually using Linear Drag, but I just didn't notice you modify that value that's why it was weird. Also thank you for the additional tips!
Thanks for the tutorial, not just for this one, but all of them are superb! One advice tough, if I may: don't fastforward your tutorials please. It's really, really, really hard to follow. I get it, that 30 min tutorials are not the most ideal, but it takes way longer (at least for me) to alway go back to x minute : y second, try to stop it, to see what was going on there, then rinse and repeat.
Hey thanks for the videos, however don't speed up your code so fast we have 0.5 seconds to read it (Ex. 8:47). I'd rather have a longer video that a human can follow rather than this annoying rewind process. Again, thank you for the content you provide to the community!
You are supposed to hit the pause button, the goal is to learn not to just watch the video. Take your time and make sure you understand everything, this is your learning journey.
@@CodeMonkeyUnity True, I program for school, I program for finance and so by the time I get to unity and C# I just want my specific project to get done the way I want however I agree slow and steady yields better results.
I totally agree with u, the tutorials are awesome but code monkey is waaay too fast i find myself having to go back over and over again. Even if you try to pause the video the code is already gone. Even slowing the video down is not enough
thank you so much. i thought i was the only one getting this error. after troubleshooting, it couldn't possibly be anything with the code or objects, so I gave up for a couple hours until I found ur comment!
@@_At0mz I am not sure but the reason is possibly awake functions. I also got different errors tho :) decided to implement inventory thing with other simple approaches wiht chatgpt:).
A Weapon Hotkey Bar is something I'm working on and Crafting is also something I'd like to cover. Currently working on recreating Terraria in Unity which requires both those things.
Awesome tutorial, modified it a little bit to fit the inventory system I am making, but all the info I needed was here. Thank you so much for this information-packed, yet short and easily understandable tutorial.
To fix the issue at 7:40 I did this: private void RefreshInventoryItems() { int x = 0; int y = 0; float itemSlotCellSize = 100f; foreach (Item item in inventory.GetItemList()) { RectTransform itemSlotRectTransform = Instantiate(itemSlotTemplate, itemSlotContainer).GetComponent(); itemSlotRectTransform.gameObject.SetActive(true); itemSlotRectTransform.anchoredPosition = new Vector2(x * itemSlotCellSize, -y * itemSlotCellSize); x++; if(x >= 4) { x = 0; y++; } } } Hopes this helps, I ended up downloading the project off his website and looking at the code rather than the video, took me an hour to get working lol..
@@xmimagma4630 Hello, to clarify its exactly what he shows in the video, however, its shown later in the video. So where i followed along it didnt work for me. So, naturally, I did bug testing myself thinking it was my mistake, but it if i remember correctly if you dont watch the entire video before attempting it yourself first, its quite awhile ahead (the solution he provides).
@@xmimagma4630 So, I thought if anyone else ran into the exact problem i had. Where there was an error (like i had). That they might look at the comments and see what i posted :)
How did you do to implement the part of the "ItemWorld"? I mean, 3D objects are not sprites, so you cannot do what he does in the video. What components did you add to the ItemWorld in the Hierarchy?
Hi! For some reason i can't see the items like you do 7:00, is there a way to fix this? (i also have another script added to the UI, which open and close the inventory with I)
2 years late, but I found that I had renamed the image within the inventory container, so it was trying to find an object called "image" and i'd renamed it to SwordIcon or something like that. Just make sure the names of your objects the script is looking for match.
Awesome tutorial! Thank you very much! You kinda sound like Kermit the Frog. That's a good thing! Great quality voice, I could listen all day. No word whiskers, no umms. I wish I could give more than one thumbs up! You Rock!
Hey Code Monkey. Great video, really interesting and helpful. I was simply wondering if there was a way to integrate scriptable objects with this inventory system in the event that someone has a lot of items in their database. I created a class that has the needed parameters like item name, its function, the amount and the sprite graphic, but I seem to be having trouble integrating it with your enum approach. Do you have any suggestions?
Yup, I actually built upon this system to make a Crafting System and use Scriptable Objects for the items and recipes th-cam.com/video/E91NYvDqsy8/w-d-xo.html
Hey! To all the people that have a NullReference error in their UI_Inventory about not finding the Image component: Be sure that you didn't do any typo, some lines are very case-sensitive. AND Check that your Image game object of the ItemSlotTemplate has the "Image" component and not something like a "Sprite Renderer". It will maybe not solve your error but I hope it will help someone else. ;)
it gives me this problem , im trying to fix this since hours without results.. NullReferenceException: Object reference not set to an instance of an object UI_Inventory.RefreshInventoryItems () (at Assets/Scripts/UI_Inventory.cs:33) UI_Inventory.SetInventory (Inventory inventory) (at Assets/Scripts/UI_Inventory.cs:20) PlayerMovement.Awake () (at Assets/Scripts/PlayerMovement.cs:18) i was at 9:09 . I put all the sprites into the game object (ItemAssets) but it doesnt work.
Ok, I figured it out after a month and the fix is pure witchcraft. First I renamed Image image = itemSlotRectTransform.Find("image").GetComponent(); to Image image = itemSlotRectTransform.Find("Image").GetComponent(); and then duplicated item assets game object and it worked
@@CodeMonkeyUnity yeah i think that the problem is the name of image ,i had named it "Item" even if in the script i was searching for "image". Ty for the help :p
For anyone in this case, at 19:55 I thought this was the same text object but this is a different class (because not in a Canvas). Maybe I should have watched the UI tutorials beforehand :3
I find really difficult to follows your videos. It may depends by the fact that I am a beginner, and you skip a lot of explanations. I am looking videos for learn and not for copy your code, I would like to master the code so I can make it my own, and add the relative fix/adjustments.
Start off with the Basics th-cam.com/play/PLzDRvYVwl53vxdAPq8OznBAdjf0eeiipT.html And then make Flappy Bird th-cam.com/video/b5Wpni9KPik/w-d-xo.html If you follow all that you will gain a nice knowledge base to draw from
Thank you for good example. Questions: 1. Why you did attach to Item prefab (pfItemWorld) the Rigidbody2D also? For raise the OnTriggerEnter2D it's enough to attach only the Box Collider 2D&? Source text 2. What is the reason for the strategy of replacing the "ItemWorldSpawner_ *" game object (placed in the Unity Game Designer editor) at the game init stage by new instantiated objects based on pfItemWorld? Why doesn't it put the appropriate prefabs (pfItemWorld_sword, pfItemWorld_health and others) into the Unity editor from the very beginning? I saw only one reason - make less the Level size on disk (because the size of "ItemWorldSpawner_ *" less than "pfItemWorld_sword"), Is it? May be but is it efficient ? - You save place on disk, but load game will be more slow, because it demands time to create new gameobjects?
I get NullReferenceException: Object reference not set to an instance of an object UI_Inventory.Awake () (at Assets/UI_Inventory.cs:17) and NullReferenceException: Object reference not set to an instance of an object Player.Awake () (at Assets/Player.cs:26) hmmmm
manaiged to get it down to just this error NullReferenceException: Object reference not set to an instance of an object UI_Inventory.RefreshInventoryItems () (at Assets/Scripts/UI_Inventory.cs:38) UI_Inventory.SetInventory (Inventory inventory) (at Assets/Scripts/UI_Inventory.cs:23) Player.Start () (at Assets/Scripts/Player.cs:27)
This is great! Thank you Mr CM. I am your Udemy student and wondering how can i make this with Bolt. What do you suggest. Because i cant understand what is going on at the scripts.
Doing this exact system with Bolt is a bit tricky since it uses custom classes and enums. The easiest way with bolt would be using Transforms for the items kind of like how in the course I handle the Key Door System
Probably the the most confusing tutorial I have ever watched. I felt like he just wants you to copy him. Really hard to follow, not teaching anything. If you are a beginner, just find someone else.
@@CodeMonkeyUnity Well, I managed to follow until ItemWorldSpawner. It took hours just to get there. And when I got another error I was frustrated and quit watching (And deleted the scripts). This might be a very comprehensive inventory system(which really does seem like) but definetly isn't "great simple".
@@mephisto95 Ive gotten countless errors by following exactly what he did in the video, only to fix it by doing something not shown in the video. Now my inventory container is not spacing properly. Ive followed every step exactly and for some reason his result is completely different. Im just tired and done with this tutorial its my 2nd day trying to follow it, I have work to worry about. Im not paying for his course. Im just going to watch Brackeys inventory guide
@@mephisto95 It's as simple as an inventory system can be. You can maybe find some "simpler" ones that just store a list of Transforms, but the second you try to implement that kind of system in your own game with your own items you will quickly realize what a mess it becomes. I'm trying to teach the simplest method possible while writing good clean code, I refuse to teach you bad practices just for the sake of making it "simpler"
The only outdated thing in this video is that it was made when the Universal RP was still named Lightweight RP so you need to rename the class names and namespaces. But all that affects are the lights, all of the inventory logic still works exactly the same.
I’ll try again but at 9:10 when I put the sprites in the editor I keep getting null ref errors and only 1 sprite shows up 3 three times. Then I can’t even open the scene after I close unity.
So I was able to fix the null ref errors but I’m getting stack overflow errors. Now unity crashes when I implemented the UseItem function. I can’t even run debug.log to see the issue.
FYI for null errors! If you are getting null reference error on your script (associated if sprite), try to put item assets script to run first before everything else (Code Monkey has some video about it). I was trying to figure out why everytime I quit unity and open the scene again this null reference error keep appearing and I had to recreate the item assets.
Excellent tutorial, as always! Though as a beginner i cant understand why we don't want a reference to the Player.cs on our Inventory.cs (24:59) and why is method UseItem() defined on Player.cs instead of Inventory.cs. Isn't item behaviour on use always the same and not related to the player?
Hi, great tutorial and I know this tutorial is old, but I am just wondering how to make a full inventory, so if the inventory is full you can’t pick up items anymore.
That's not true, if you keep at it you will learn, it's all about experience. Remember that when you watch my videos that I did not learn all this in just 20 minutes, I've been programming for 20 years and there's mountains of research behind what you see in the final video. So keep at it, keep learning and it does get easier.
@@CodeMonkeyUnity Thank you so much for your words. I greatly appreciate you and everything you do for this community. You have enabled the world of game dev to me, and through that it has gotten me through some hard times. Thank you for who you are and what you do. Thank you truly.
Hi CodeMonkey, can we drag and drop stored items in another inventory(UI) according to order from this tutorial, I'm very new just following your videos and doing my project. I will really appriciate your help. Thanks!!!
Amazing video, I only have a little code background but I learned so much while watching this. I'm running into an issue where if I use an item in my inventory, if there's only one item left in a stack it's not removing it, or at least not removing the item slot container from the inventory. Any tips or solutions?
It doesn't remove the last one? Sounds like your logic is only decreasing the stackAmount and never testing if it's 0, if it is then it should remove the item itself
Thanks for the tutorial I learned a lot! You cover a lot here in a short time I like how you speed up the tweaking when you hop in the Unity editor it really trims the video down and when I had a question about how your scene was setup I was able to just go back and slow playback speed to see how you setup your UI elements in more detail.
I'm getting super overwhelmed with inventory and data storage management/logic. I'm starting to realize why so many games just stick with very simple inventory systems or just don't even do them at all. Even just trying to copy something like animal crossing that seems super simple gets overwhelming. Like if you stick an item in the middle of an inventory with 1000 items in it do you literally push back every single item behind it? Actually now that I'm typing this I realize they probably just save items in their categories and just load new categories at the end of the old one. Still I think its way more complicated than it actually seems.
Great tutorial but a bit too complex for my current level...got stuck for 4th time trying to make this work the items are not appearing in inventory after adding the right visuals....
i have some error when i doing a spawner item world 15:00 can you help me ? NullReferenceException: Object reference not set to an instance of an object ItemWorld.SpawnItemWorld (UnityEngine.Vector3 position, Item item) (at Assets/Inventory/Script/InventoryScript/ItemWorld.cs:11) ItemWorldSpawner.Awake () (at Assets/Inventory/Script/InventoryScript/ItemWorldSpawner.cs:11)
Is this same methodology used when handling hundreds of items? Or is there a better way to build out the library over the ItemAssets class in this video?
I'm having a problem with my buttons. They seem to be three times as big as they are supposed to be. Whenever I click on the space anywhere near them, it uses them. Is there a way to adjust the size of the button?
Do you have any recommendations for your videos that would help implement accessing all the items that have been added to the Inventory list? So you can use that info to say display how much ammo you would have for a weapon. Thanks for all the videos!!
Hmm the closest thing I covered was the Item Inspect System th-cam.com/video/tJ_ycboPFmY/w-d-xo.html You click to select an item then look at its 3D Mesh. You just need the click logic then display whatever data you're storing in your items.
Also Ive been trying to use your Key/Door tutorial with this tutorial to just access one list of items. I just cant seem to grasp what i may be doing wrong. I have added this to the inventory script to the main inventory script, public bool ContainsKey(Item item) { return itemList.Contains(item); } this was on the keyDoor script public Item.ItemType GetItemType(){ return itemType; } and then this on the main character for when entering the collider if(inventory.ContainsKey(keyDoor.GetItemType())) {////MY UNLOCKING PROCESS////} So my problem is when I save, it returns the error cannot convert Item.ItemType to Item, which Ive read is trying to compare the enum Int value with the string of the actual item. So I thought hey try public Item GetItemType(){ return itemType; } on the door, which did result in no errors but no working unlock. So I was wondering if you may lend some more insight on this dilema! Thanks for all the videos and congrats on your award!
@@MichaelHeist That should work, why is the unlocking not working? Seems like it's related to the unlock logic and not the identify key logic. Add some Debug.Log to see what your code is doing
@@CodeMonkeyUnity I know, I could have sworn it would have worked. As for the Debug it would return the word item, if it typed item.itemtype then I get the correct results, which was weird. For now I just went with a foreach loop on the get item list, when you enter the collider. Which does work but didn’t seem as efficient as just checking the one item. But I know I’ll revisit this issue when I go back and revise some things. Thank you once again for what you do.
it works perfectly but i was wondering how would i make a simple crafting system like when i want to make a building that needs 2 woods and 3 gold,if i have the required materials needed to build in my inventory , the materials gets used up from the inventory.. something like this.. how would i approach this?
at 5:52 he is dropping the UI_inventory to the inspector. When I'm doing that part, it doesn't allow it. It only lists my Player as only reference available. What I am doing wrong? At times it's little hard to follow, because UI_inventory script and gameobject is named the same, so I'm not always sure which one the reference should apply to.
help!!!, when I click, it does nothing, I already download and compare it but they are the same, the layouts, the inputs, everything, I already debug it and if it enters Button_UI but when it clicks it does not respond, please help!
Here's a great simple but also very robust Inventory System! You can apply this to Enemies and make them drop items on Death!
Play 7 Awesome Games (Action, Strategy, Management) and Help Support the Channel!
Get the Game Bundle 67% off unitycodemonkey.com/gameBundle.php
Simple yes, but not robust.
You need more abstraction for robust code.
For stable and flexible systems try to use "solid principles". These are amazing.
@@acp9477Can you recommend anything ? We will be grateful )
"StackOverFlowException: the requested operation caused a stack overflow" Error
Help me, I dont Understand why i have this error
Hi, i download your pkg, but it dont work for some reference miss... The Ligth2D is non fuond O.o
i dont mean to be off topic but does anybody know of a method to get back into an instagram account??
I was stupid lost the login password. I would love any tips you can give me!
The fact that this is considered "simple" inventory system is really just a testament to how deceptively tricky these systems really are. Great tutorial though, really does help a lot once you hit the point of understanding a lot of the fundamentals of the Unity engine.
1:32 Item List
3:50 UI visuals
5:20 UI script
7:40 Proper visuals on each item
9:12 Pickup item world
11:55 Lights(skipped)
12:20 Pick up item
13:30 Update inventory
15:00 Spawn items in world
16:50 Stacking items
18:20 Display amount
20:40 Use and drop items
23:00 Improved Drop
u are a goat
Is there saving and loading shown in this tutorial?
Thank you
Yeah this system will have Save and Load?
Whenever he says "and here its very simple.." , slow the video down to 0.25
LOL TRUEEEE.
Great video! Learned a lot more about Unity compared to the others I have followed. Though, due to a mistake I had to restart this from scratch. The cloning of the 'itemSlotContainer', and 'itemSlotTemplate' wasn't an issue before; now it's an obstacle since the cloning are now stacking on top of each other instead of a grid-like structure. If anyone has any pointers to how to fix this would be greatly appreciated. Thank you for your time.
SOLVED: Make sure you put "int x = 0;", "int y = 0;", "Float itemSlotCellsize;" BEFORE the foreach. As all programmers know, lethargy is a pain, and brain fog is bound to happen. Keep on, keepin on!
Like a lot of people in watching this video, I've been trying to knock this out, and after a solid week of trying, failing, and starting over, I finally managed to make it to the credits of a video about this. While there are still a mountainous number of issues left to work out, you sire have earned another shout out in my dev log. Hope you tune in to see it!
Nice! The devlogs have a really interesting style, best of luck with the game!
@CodeMonkeyUnity Thanks for watching! It really means a lot to me.
I just posted a new entry discussing all of this inventory stuff yesterday, and you're featured in it! Give it a watch when you can 😁
I was going through some other tutorials where the video creators just expected you to have magically watched the other 100 or so videos in their channel, and didn't explain anything of what they were doing
Seeing you reply to people even in this video of 3 years ago (and also still keeping the project public) makes me truly admire you and your work, a glimpse of hope in this hellhole where people literally just want to learn. Thank you for doing what you do to this day man.
I'm glad you found the video helpful! Best of luck with your project!
5:56 I would recommend calling
inventory = new Inventory();
uiInventory.SetInventory(inventory);
in Start() instead of Awake() - When called in Awake it can break because of the dependencies in UI_Inventory and ItemAssets, which both are also called on Awake and cause mistiming.
Had that same issue as both were being called in Awake, yet one wasn't ready yet.
I was having a problem and this fixed it, thanks!
dude, thanks so much, I was having problems with that
thank you
I got crazy for 30 min looking for this error, thanks man!
I watched this video so many times (in parts of the video), I just got your "How to fix NullReferenceException in C#" video as a YT ad on this video. This tutorial is called "simple" but it is the most densely edited, long tutorial, covering a lot. I have underestimated your patience and experience level :3
there is 2 types of people in the world:
A: public void a() {
}
B: public void b()
{
}
B is the only acceptable one
@@captainoblivious_yt +1
@@captainoblivious_yt +7000000000 except Brackeys and CodeMonkey
@@captainoblivious_yt +
For those that tries to do this tutorial and faces the exception about nulled references from inventory, this is because they use the Awake() function. Because of this some scripts are not yet initialized and therefor you get the errors. Solution is to either change Awake() to Start() and hope they get executed in the right order, or go to script execution order in the Project settings and set the order on how it is supposed to work.
I've seen these issues in alot of tutorials where the Awake function is used to get the editor in unity updated quickly.
Thank you so much for this! I was facing the same trouble and KNEW there was somewhere to make this change, but wasn't familiar with it exactly.
your such a big help thank you i have spent like 2 hour troubleshooting this and sifting through the comments thank you so much
Fking love you for this
you save my dayy
Worked!!! Thanks!!
I cant even comprehend how code monkey talks to people, every single day a ton of people chat him but he replies to every single one
It definitely takes quite a bit of time but I enjoy doing it!
@@CodeMonkeyUnity thank you for taking the time and effort ^.^ i wanted to know, will you ever give us tutorials on 3D games?
It took a bit of tweaking to get this to work in a 3D space, but this tutorial helped me understand the basic logic behind how an inventory works in a game. Great tutorial! Looking forward to learning more from you.
I'm glad the video helped you! Thanks!
how did you replace the sprite renderer in itemworld for 3D??
@@Ultratermin8or i THink u need to import 2D options to the 3d Unity
@@Ultratermin8or Instead of using a sprite renderer replace the function with Mesh. It works the same
@@dapizzaking4455 Whats the function, I understad that I need to change it, but I dont know how to write it :c
This took me a long time to figure out, but for those using more recent versions of TMP, it seems they refactored it to only need TextMeshPro without the UGUI and Canvas Renderer stuff, so if you're getting null reference exceptions, that could be one reason. Another thing that took way to long to figure out is that script execution order REALLY matters to this system and I wound up placing the Item Assets and UI scripts BEFORE default time in order to get it to run and force their Awake methods to call.
i might've the same problem "CS0649 player.uiInventory is never assigned to" even though I assigned as at 5:48. can you elaborate more how you fix it.
edit: fixed, Edit - Project Settings - Script Execution Order, then put UI_Inventory before Player so that the script exist when Player asked for it
so what changed for the TextMesh? I cant seem to change the text no matter what i do. NullReferenceException.
Agree, thanks.
@@benharik5002 Thank you so much, took me like an hour to figure tis out.
OMG I DID IT, only took me 7 days to follow this tutorial for my 3d game xD
Nice! Great job on taking your time and really learning!
Man... you are amazing! Thanks for this complete tutorial. I hope one day I’ll be as good as you are and, then, be able to teach other people. 😀
It's all about experience! Just keep writing code and building systems and you will get there!
i know this video is old but for anyone wondering on how to limt items stacking, i made for the inventory script to add ........ if (inventoryItem.itemType == item.itemType && inventoryItem.amount != item.maxAmount) and for item script to add public int maxAmount (p.s. im very new to codeing,so tell me if im wrong so i can improve )
Me: Watches Tutorial, all looks good.
CodeMonkeyUnity: *creates Inventory Interface at Super Speed*
Me: even at 0.25 speed its to fast to follow...
Love how you went x1000 speed when doing the background images for items was super easy to follow
Your game is certainly going to have a very different visual from mine, the important part is how the code works, not how it looks
dont cry lol
Can you stop stalking me xD
I just wanted to start with the inventory system xD
Every single time, huh? XD
Literally same here
Me: stopping the video multiple times on 0.25x speed
It did help and saved my huge time for my project... Thank you so much!!
Refreshing inventory should be done in a better way, this way is really taking on the performance. In case you get more than 20 items you gonna notice big spikes when inventory changes.
Other than that, very cool
Hey man, I'm kind of a beginner, and I was gonna implement an inventory system with the logic used in this, but I just cant seem to understand how the Item can simply be passed in to the UseItem function. Does it not need a reference or the enum to be set to that particular item to tell which item the player is using, or does it actually know that from a particular logic?
Your comment is monthes old so idk if you still don’t know, but basically the UseItem function is taking in arguments (the extra stuff in the parantheses next to “UseItem”) which, in simple terms are basically bits of information necessary for the function to run. They also serve as a reference to whatever data is sent into that function, so by calling the function and sending in the item, you are effectively creating a reference to said item
i wish you would explain why you are doing what you are doing and not only state what you are doing... brackys for example explains why he chooses to do what he is doing and dont just state what he does.. for example.. if you made enum or a certain function or constructor you need to explain why did you choose this method and how it functions in the game... this is what makes a teacher a great teacher. thanks.
I assume you know the basics of Unity and C# and with that you should be able to follow everything.
What part couldnt you follow? If I explain what is a function and what is a variable in every video then all my videos would be 2 hours long.
It's not my place to say this, but I'll say it anyway. That is not how FREE tutorials work. The way he teaches is different than Brackeys and some people like that, others don't. I don't see where CM is getting paid to do this or satisfy anyone, so... Please think carefully before comparing people and choosing words like "you need to do such and such." Thanks.
Subscribed for the good quality tutorials
and the the way of reveling the basics
Thanks!
8:36 that switch functions looking handy
You did great on this but the speed is a little frustrating to keep up with.
Coming back four months later to do it again and holy cow, applying this to VR is aggravating.
@@Wayloz this is an infuriating tutorial to follow. Im done, starting over with someone elses video
took me some days but finally finished the tutorial, after countless stops to "do my stuff", which means, doing unrelated things like the start of a hotbar system and... decompiling a game to modify it too, i guess
I like your process of fast forwarding the video when there's tedious bits, but I think this is terrible for anyone new that wants to actually learn what you're doing :(
I watch it in 0.25 speed, it's a messy workaround, but it works! 😆
This is an okay inventory system, to make it more scalable, I switched to using ScriptableObjects for the items allowing me to store the item details in that S.O., ie name/sprite/etc. I also setup the InventoryUI to be able to dynamically create slots as needed. that way if I want different sized inventories or items that add more slots i can create logic to handle it
I'm trying to do the same thing, how did you link it all together ?
Assets\Scripts\ItemWorld.cs(28,38): error CS1061: 'Item' does not contain a definition for 'GetSprite' and no accessible extension method 'GetSprite' accepting a first argument of type 'Item' could be found (are you missing a using directive or an assembly reference?)
Does anyone know how to repair this?
To those that are stuck on the useitem (timestamp starting at 20:40) portion (where you left-click on a non-stackable item and it doesn't remove from your inventory) - I did away with the "if(item.IsStackable())" condition within the "RemoveItem" method and now my inventory is working as expected (decrementing an item in the inventory down both for stackable and non-stackable items).
What I found is that the IsStackable condition was the only one being allowed to decrement the count or amount on the item and anything else was not being included in the logic. I reviewed that section and other sections of this video at least 5+ times and confirmed my code was a 1:1 match to the code content.
So either something changed in Unity (this video is 3+ years old, so wouldn't surprise me), something is bizarrely different in my project (which is weird because I saw others had a similar problem based on the comments), or the logic being provided in the video is flawed and was updated without an update to the video.
I even created a shit-ton of debug.log statements (which seems to be the only feedback that was given by CodeMonkey in the comments - aside from ghosting others) and I got a big nothing out of doing that. I'm glad that I finally got my inventory to work, but man was it a pain in the ass to get that last bit working.
Quick Edit: I discovered that dropping items becomes an issue for non-stackable items if you have more than one of that same item in the inventory (makes sense since it's just decrementing regardless of it being stackable or non-stackable) - To avoid further headache, I just made two separate methods (one to remove items and one to drop them) - the drop method is just the original code from the video for remove item (since the drop item was the only function that worked for me previously) and then have the remove item (code below) for decrementing the item when using it.
Here's the code section for the Inventory class in case anyone wanted to try this solution in their project:
------------------------------------------------------------------------------------------------------------------------------------------------------------
public void RemoveItem(Item item) {
Item itemInInventory = null;
foreach (Item inventoryItem in itemList)
{
if (inventoryItem.itemType == item.itemType) {
inventoryItem.amount -= item.amount;
itemInInventory = inventoryItem;
}
}
if (itemInInventory != null && itemInInventory.amount
From what you mentioned there's nothing specific to any Unity version, C# is still exactly the same C#, it's just logic, completely separate from Unity versions.
The only possible feedback I can give you is indeed add tons of Debug.Log(); to see what your code is doing.
Code is deterministic, if you write the exact same code you will get the exact same result so you clearly have something different, I can't magically tell you what.
Instead of looking in the video you can download the project files and compare directly with your own
You're an angel! Thank you!
@@CodeMonkeyUnity First of all, I have to say thank you so much for all of your hard work with your tutorials. They have helped so much in understanding programming and unity in general and I genuinely feel that I would not have progressed even half as far without them. I have even purchased your Builder/defense course as well as visual scripting courses which I highly recommend to anyone wanting to learn! (They're very helpful! and fun with a nice pace that isn't dull at all imo)
That being said..... This tutorial along with the drag/drop and Equipment tutorial are a pain, They just don't work, whether or not it's errors because of script execution order (using awake to get references along with alot of recttransform finding, just is not good practice for a system that needs so many references. I get that you want to be a purist and do everything through code, but I have to say that while I limit my use of the inspector...I have NEVER (maybe I'm lucky? dunno) had a problem with script execution order when I just drag and drop the needed references and make a prefab.
I did download the project files from your (what I considered to be final version) equipment tutorial and there were some extras like "GetInventorySlotWithItem(item).RemoveItem();" which maybe could just be for the equipment, but it says for all inventory slots which is not included here, but being exactly as it is in this tutorial, dropping items works fine, but using them does not remove the last one from the inventory and you can use it indefinitely.
side note: I get that this is supposed to be a "simple" inventory system that you state could be expanded upon, but this is a really poor way to implement inventory.
Items SHOULD be scriptable objects where we could just add a sprite etc to represent the visuals. Who in their right mind would want to do this " in one class have to add public Sprite oneHandedswordSprite; , and in another class case ItemType.OneHandedWeapon: return ItemAssets.Instance.oneHandedswordSprite;" for EVERY single item in the game (not to mention having to add ACTUAL functionality like effect, stat bonuses, Set bonuses etc)!?! Sure, this could if you only had a handful of items in the game, but if you only had a handful of items why bother with this over complicated approach? creating an elaborate inventory system that is only manageable on a micro level is is bad game design and while most players want depth to their games, this isn't depth...this is the illusion of depth. Like claiming a game has rpg mechanics because every time a player levels up they do +1 damage. Most people would just rather not have a shallow system vs a real one. This system doesn't provide a realistic way to build further upon (unless you're a masochist), so it's just not worth using.
I'm sorry for the rant, and I love your channel and everything you do for game developers, but this (in my opinion) should be remade or removed entirely) This is honestly the only video series from you that made me think "why is he teaching how to dig a miles long trench...with a plastic spork!?".
Is there any chance you could remake this with your newer code? I tried to convert this to the drag-drop armor equip and it's completely different. Thanks!
Nice tutorial as always, were making our very first game project at Uni so this was valuable inspiration of how you could do an inventory
If anyone has problems with the clicks registering outside the visual box in the inventory: Make sure the Rect Transform of all the objects in the ItemSlotTemplate are inside the actual box. My text showing the amount was set to 200 width and I couldnt figure out why the clicks registered so far to the right of the icon.
Yeah always be careful with regards to the actual size of the objects especially when dealing with Images that have lots of transparent pixels
When making tutorials like these do you have all this memorized and understood or do you go back to documentation every once in a while?
There is always a lot of research that goes into making a video. What you see in the recording is after I've already written and rewritten everything 2-3 times. That's why I always tell people that they're not expected to follow the tutorial in realtime because even with all my knowledge I definitely don't build these systems the first time in just 20 mins.
And yup I google things all the time. For simple things like this inventory system, which I've probably written 20 inventory systems in my decade of making games, for this I don't need to google much but for more complex topics yup all the time.
@@CodeMonkeyUnity thanks for the reply! That’s reassuring to me as a beginner that even the pros need to Google a bit. I’m extremely reliant on chatGPT in understanding the concepts used which makes me feel bad. But I ask it to explain the process step by step to understand exactly what’s going on so I can hopefully some day become less reliant on it🙂. Thanks again for working hard to produce amazing quality tutorials for us less fortunate enough to afford a college education ❤️
You are awesome! Thanks for doing this, your lessons have helped a lot of people achieve their goals :)
Thanks! I'm glad to hear it!
I've got a LOTTT of learning to do
Keep at it! Learning is a continuous journey!
I've implemented a drop item system in my own game, but the "spawn" of the items, I made without rigid body, and rather with a lerp (and coroutine). I've noticed your approach with add force, and I find it way cleaner/simpler and probably even safer. The issue I ran into on the other hand is that my Item seems to slide to infinity after spawning. I wonder why is that. Are you using some kind of physics material on your ground? If I add angular drag to my object it stops correctly, but otherwise can't seem to get it work. Cheers and keep up the awesome tutorials! (P.S. It might be a little fast paced for beginners, but I can tell you that as an advanced Unity developer, I can follow along nicely)
No need for any special material, just set the Linear Drag to more than 0 and it will stop.
If performance is an issue you can either do the drop animation through code moving the transform or remove the Rigidbody once its stopped.
@@CodeMonkeyUnity Yea, I did fix it eventually using Linear Drag, but I just didn't notice you modify that value that's why it was weird. Also thank you for the additional tips!
Thanks for the tutorial, not just for this one, but all of them are superb! One advice tough, if I may: don't fastforward your tutorials please. It's really, really, really hard to follow. I get it, that 30 min tutorials are not the most ideal, but it takes way longer (at least for me) to alway go back to x minute : y second, try to stop it, to see what was going on there, then rinse and repeat.
Great stuff! Thx! 👍🤓
Thank u for advertising, bro! During your advertising, TH-cam does not interrupt to another :)
Hey thanks for the videos, however don't speed up your code so fast we have 0.5 seconds to read it (Ex. 8:47). I'd rather have a longer video that a human can follow rather than this annoying rewind process.
Again, thank you for the content you provide to the community!
You are supposed to hit the pause button, the goal is to learn not to just watch the video.
Take your time and make sure you understand everything, this is your learning journey.
@@CodeMonkeyUnity True, I program for school, I program for finance and so by the time I get to unity and C# I just want my specific project to get done the way I want however I agree slow and steady yields better results.
I totally agree with u, the tutorials are awesome but code monkey is waaay too fast i find myself having to go back over and over again. Even if you try to pause the video the code is already gone. Even slowing the video down is not enough
If you get object reference error at 16:40, Edit > Project settings > Script execution order > Add ItemAssets on top of the list.
thank you so much. i thought i was the only one getting this error. after troubleshooting, it couldn't possibly be anything with the code or objects, so I gave up for a couple hours until I found ur comment!
@@_At0mz I am not sure but the reason is possibly awake functions. I also got different errors tho :) decided to implement inventory thing with other simple approaches wiht chatgpt:).
Can you make a tutorial on how to equiped weapons from your inventory and one on how to craft items from your inventory pls.
A Weapon Hotkey Bar is something I'm working on and Crafting is also something I'd like to cover.
Currently working on recreating Terraria in Unity which requires both those things.
Awesome tutorial, modified it a little bit to fit the inventory system I am making, but all the info I needed was here. Thank you so much for this information-packed, yet short and easily understandable tutorial.
Thanks! I'm glad you found the video useful!
how do i ask if an item is already in the inventory in an if() statement?
To fix the issue at 7:40 I did this:
private void RefreshInventoryItems()
{
int x = 0;
int y = 0;
float itemSlotCellSize = 100f;
foreach (Item item in inventory.GetItemList())
{
RectTransform itemSlotRectTransform = Instantiate(itemSlotTemplate, itemSlotContainer).GetComponent();
itemSlotRectTransform.gameObject.SetActive(true);
itemSlotRectTransform.anchoredPosition = new Vector2(x * itemSlotCellSize, -y * itemSlotCellSize);
x++;
if(x >= 4)
{
x = 0;
y++;
}
}
}
Hopes this helps, I ended up downloading the project off his website and looking at the code rather than the video, took me an hour to get working lol..
I don't get it that's exactly what he shows in the video... Or I might be being stupid. What did you change?
@@xmimagma4630 Hello, to clarify its exactly what he shows in the video, however, its shown later in the video. So where i followed along it didnt work for me. So, naturally, I did bug testing myself thinking it was my mistake, but it if i remember correctly if you dont watch the entire video before attempting it yourself first, its quite awhile ahead (the solution he provides).
@@xmimagma4630 So, I thought if anyone else ran into the exact problem i had. Where there was an error (like i had). That they might look at the comments and see what i posted :)
u teach so good 😍
Even tho i changed a lot of things to make it suitable to my 3D project this video helped me a lot, thanks!!
How did you do to implement the part of the "ItemWorld"? I mean, 3D objects are not sprites, so you cannot do what he does in the video. What components did you add to the ItemWorld in the Hierarchy?
@@natsuiro_shiroi Well I used the sprites for the inventory then created a spawner which allocates prefab items inside my map.
Hi!
For some reason i can't see the items like you do 7:00, is there a way to fix this? (i also have another script added to the UI, which open and close the inventory with I)
Hey 5 Months late to your comment. Did you ever find a solution I'm having this same problem
@@ItsDurry Same problem
2 years late, but I found that I had renamed the image within the inventory container, so it was trying to find an object called "image" and i'd renamed it to SwordIcon or something like that. Just make sure the names of your objects the script is looking for match.
Awesome tutorial! Thank you very much! You kinda sound like Kermit the Frog. That's a good thing! Great quality voice, I could listen all day. No word whiskers, no umms. I wish I could give more than one thumbs up! You Rock!
Thanks! Glad you found the video helpful!
Can you please not speed the video up its so irritating to pause it and write code!
Asphalt 9 Legends music is fire!
Hey Code Monkey. Great video, really interesting and helpful. I was simply wondering if there was a way to integrate scriptable objects with this inventory system in the event that someone has a lot of items in their database. I created a class that has the needed parameters like item name, its function, the amount and the sprite graphic, but I seem to be having trouble integrating it with your enum approach. Do you have any suggestions?
Yup, I actually built upon this system to make a Crafting System and use Scriptable Objects for the items and recipes th-cam.com/video/E91NYvDqsy8/w-d-xo.html
Thank you so much for taking the time out to reply. It's greatly appreciated. Loving the tutorials. Keep it up!
Hey! To all the people that have a NullReference error in their UI_Inventory about not finding the Image component:
Be sure that you didn't do any typo, some lines are very case-sensitive.
AND
Check that your Image game object of the ItemSlotTemplate has the "Image" component and not something like a "Sprite Renderer".
It will maybe not solve your error but I hope it will help someone else. ;)
Yup case sensitive is usually the issue, whenever you get nullRefs use Debug.Log to identify what is null unitycodemonkey.com/video.php?v=5irv30-bTJw
it gives me this problem , im trying to fix this since hours without results..
NullReferenceException: Object reference not set to an instance of an object
UI_Inventory.RefreshInventoryItems () (at Assets/Scripts/UI_Inventory.cs:33)
UI_Inventory.SetInventory (Inventory inventory) (at Assets/Scripts/UI_Inventory.cs:20)
PlayerMovement.Awake () (at Assets/Scripts/PlayerMovement.cs:18)
i was at 9:09 . I put all the sprites into the game object (ItemAssets) but it doesnt work.
Same here bro
Ok, I figured it out after a month and the fix is pure witchcraft.
First I renamed
Image image = itemSlotRectTransform.Find("image").GetComponent();
to
Image image = itemSlotRectTransform.Find("Image").GetComponent();
and
then duplicated item assets game object and it worked
Find(); is case sensitive so the name must be exact. "image" is not the same as "Image"
@@CodeMonkeyUnity yeah i think that the problem is the name of image ,i had named it "Item" even if in the script i was searching for "image". Ty for the help :p
For anyone in this case, at 19:55 I thought this was the same text object but this is a different class (because not in a Canvas). Maybe I should have watched the UI tutorials beforehand :3
I find really difficult to follows your videos.
It may depends by the fact that I am a beginner, and you skip a lot of explanations.
I am looking videos for learn and not for copy your code, I would like to master the code so I can make it my own, and add the relative fix/adjustments.
Start off with the Basics th-cam.com/play/PLzDRvYVwl53vxdAPq8OznBAdjf0eeiipT.html
And then make Flappy Bird th-cam.com/video/b5Wpni9KPik/w-d-xo.html
If you follow all that you will gain a nice knowledge base to draw from
yep pls code monkey learn to chill down
Thank you for good example. Questions:
1. Why you did attach to Item prefab (pfItemWorld) the Rigidbody2D also? For raise the OnTriggerEnter2D it's enough to attach only the Box Collider 2D&?
Source text
2. What is the reason for the strategy of replacing the "ItemWorldSpawner_ *" game object (placed in the Unity Game Designer editor) at the game init stage by new instantiated objects based on pfItemWorld? Why doesn't it put the appropriate prefabs (pfItemWorld_sword, pfItemWorld_health and others) into the Unity editor from the very beginning? I saw only one reason - make less the Level size on disk (because the size of "ItemWorldSpawner_ *" less than "pfItemWorld_sword"), Is it?
May be but is it efficient ? - You save place on disk, but load game will be more slow, because it demands time to create new gameobjects?
I get
NullReferenceException: Object reference not set to an instance of an object
UI_Inventory.Awake () (at Assets/UI_Inventory.cs:17)
and
NullReferenceException: Object reference not set to an instance of an object
Player.Awake () (at Assets/Player.cs:26)
hmmmm
manaiged to get it down to just this error
NullReferenceException: Object reference not set to an instance of an object
UI_Inventory.RefreshInventoryItems () (at Assets/Scripts/UI_Inventory.cs:38)
UI_Inventory.SetInventory (Inventory inventory) (at Assets/Scripts/UI_Inventory.cs:23)
Player.Start () (at Assets/Scripts/Player.cs:27)
You have something set to null, use Debug.Log(); to figure out what it is.
@@toweringsequoias1590 i have same error how do you solve yours
@@CodeMonkeyUnity where would I put the debug.log line?
still trynna figure it out >
@@toweringsequoias1590 Wherever you have that error, add Debug.Log to see the value stored on whatever object you're trying to access.
This is great! Thank you Mr CM. I am your Udemy student and wondering how can i make this with Bolt. What do you suggest. Because i cant understand what is going on at the scripts.
Doing this exact system with Bolt is a bit tricky since it uses custom classes and enums.
The easiest way with bolt would be using Transforms for the items kind of like how in the course I handle the Key Door System
Probably the the most confusing tutorial I have ever watched. I felt like he just wants you to copy him. Really hard to follow, not teaching anything. If you are a beginner, just find someone else.
What part can't you follow?
@@CodeMonkeyUnity Well, I managed to follow until ItemWorldSpawner. It took hours just to get there. And when I got another error I was frustrated and quit watching (And deleted the scripts). This might be a very comprehensive inventory system(which really does seem like) but definetly isn't "great simple".
@@mephisto95 Ive gotten countless errors by following exactly what he did in the video, only to fix it by doing something not shown in the video. Now my inventory container is not spacing properly. Ive followed every step exactly and for some reason his result is completely different. Im just tired and done with this tutorial its my 2nd day trying to follow it, I have work to worry about. Im not paying for his course. Im just going to watch Brackeys inventory guide
@@mephisto95 It's as simple as an inventory system can be. You can maybe find some "simpler" ones that just store a list of Transforms, but the second you try to implement that kind of system in your own game with your own items you will quickly realize what a mess it becomes.
I'm trying to teach the simplest method possible while writing good clean code, I refuse to teach you bad practices just for the sake of making it "simpler"
17:34 add in
if(item.amount > 1)
{
item.amount = 1;
itemList.Add(item);
}
under itemList.Add(item) to make it seperate non stackable items on pickup
hope this helps you
For anyone asking, this script is outdated. I followed this 3 times line for line and I keep getting unexplained errors
The only outdated thing in this video is that it was made when the Universal RP was still named Lightweight RP so you need to rename the class names and namespaces.
But all that affects are the lights, all of the inventory logic still works exactly the same.
I’ll try again but at 9:10 when I put the sprites in the editor I keep getting null ref errors and only 1 sprite shows up 3 three times. Then I can’t even open the scene after I close unity.
@@prod.storm3925 What null ref errors? Use Debug.Log to find out what is null th-cam.com/video/5irv30-bTJw/w-d-xo.html
So I was able to fix the null ref errors but I’m getting stack overflow errors. Now unity crashes when I implemented the UseItem function. I can’t even run debug.log to see the issue.
You know what I decided to just scrap the inventory system for my project I’ll find another method to use thanks for the suggestions earlier
This works great! But how would I put a cap on the inventory size?
Before you add an item check if the list size has space
FYI for null errors! If you are getting null reference error on your script (associated if sprite), try to put item assets script to run first before everything else (Code Monkey has some video about it). I was trying to figure out why everytime I quit unity and open the scene again this null reference error keep appearing and I had to recreate the item assets.
Thanks! From my player script I changed it from Awake to Start. Hopefully it doesn't cause any future issues!
Men It nothing's Happen
ok i am WAY under prepared for this
how can this video have dislikes???
Excellent tutorial, as always! Though as a beginner i cant understand why we don't want a reference to the Player.cs on our Inventory.cs (24:59)
and why is method UseItem() defined on Player.cs instead of Inventory.cs. Isn't item behaviour on use always the same and not related to the player?
Simply Amazing!
Very nice!!
Hi, great tutorial and I know this tutorial is old, but I am just wondering how to make a full inventory, so if the inventory is full you can’t pick up items anymore.
It's just a List of items, so just check the List.Count
If you are lost as well as I was around the spawning items part. Put the ItemWorld Script in the pfItemworld object.
Oh man, I've been scratching my head for 2 days without leaving my comp. Thx u!!!
I dont ever feel like I'm gonna be able to do code without completely relying on tutorials
That's not true, if you keep at it you will learn, it's all about experience.
Remember that when you watch my videos that I did not learn all this in just 20 minutes, I've been programming for 20 years and there's mountains of research behind what you see in the final video.
So keep at it, keep learning and it does get easier.
@@CodeMonkeyUnity Thank you so much for your words. I greatly appreciate you and everything you do for this community. You have enabled the world of game dev to me, and through that it has gotten me through some hard times. Thank you for who you are and what you do. Thank you truly.
Nice, you went as fast as possible, still taking thirty minutes, and I could barely tell what you were doing.
This is your learning journey so pause and take as much time as you need. The more code you write the easier it becomes.
Hi CodeMonkey, can we drag and drop stored items in another inventory(UI) according to order from this tutorial, I'm very new just following your videos and doing my project. I will really appriciate your help. Thanks!!!
Amazing video, I only have a little code background but I learned so much while watching this. I'm running into an issue where if I use an item in my inventory, if there's only one item left in a stack it's not removing it, or at least not removing the item slot container from the inventory. Any tips or solutions?
It doesn't remove the last one? Sounds like your logic is only decreasing the stackAmount and never testing if it's 0, if it is then it should remove the item itself
I would recommend using Scriptable objects, but maybe when he made the tutorial they weren't a thing?
Thanks for the tutorial I learned a lot! You cover a lot here in a short time I like how you speed up the tweaking when you hop in the Unity editor it really trims the video down and when I had a question about how your scene was setup I was able to just go back and slow playback speed to see how you setup your UI elements in more detail.
watch Brackeys UI inventory tutorial its so much better
I'm getting super overwhelmed with inventory and data storage management/logic. I'm starting to realize why so many games just stick with very simple inventory systems or just don't even do them at all. Even just trying to copy something like animal crossing that seems super simple gets overwhelming. Like if you stick an item in the middle of an inventory with 1000 items in it do you literally push back every single item behind it? Actually now that I'm typing this I realize they probably just save items in their categories and just load new categories at the end of the old one. Still I think its way more complicated than it actually seems.
Great tutorial but a bit too complex for my current level...got stuck for 4th time trying to make this work the items are not appearing in inventory after adding the right visuals....
i have some error when i doing a spawner item world 15:00 can you help me ? NullReferenceException: Object reference not set to an instance of an object
ItemWorld.SpawnItemWorld (UnityEngine.Vector3 position, Item item) (at Assets/Inventory/Script/InventoryScript/ItemWorld.cs:11)
ItemWorldSpawner.Awake () (at Assets/Inventory/Script/InventoryScript/ItemWorldSpawner.cs:11)
Is this same methodology used when handling hundreds of items? Or is there a better way to build out the library over the ItemAssets class in this video?
I'm having a problem with my buttons. They seem to be three times as big as they are supposed to be. Whenever I click on the space anywhere near them, it uses them. Is there a way to adjust the size of the button?
The size is based on the RectTransform size
@@CodeMonkeyUnity Ok, thank you so much!
how to limit the inventory slots from growing at y non stop?
Ok i set it up for the y to stop growing within my total number of slots required and with in my background
you should change
inventoryItem.amount -= item.amount;
to
inventoryItem.amount --;
if you want to drop one by one
Do you have any recommendations for your videos that would help implement accessing all the items that have been added to the Inventory list? So you can use that info to say display how much ammo you would have for a weapon. Thanks for all the videos!!
Hmm the closest thing I covered was the Item Inspect System th-cam.com/video/tJ_ycboPFmY/w-d-xo.html
You click to select an item then look at its 3D Mesh.
You just need the click logic then display whatever data you're storing in your items.
@@CodeMonkeyUnity Awesome thanks for the quick reply, I’ll check this out!
Also Ive been trying to use your Key/Door tutorial with this tutorial to just access one list of items. I just cant seem to grasp what i may be doing wrong.
I have added this to the inventory script to the main inventory script,
public bool ContainsKey(Item item) {
return itemList.Contains(item);
}
this was on the keyDoor script
public Item.ItemType GetItemType(){
return itemType;
}
and then this on the main character for when entering the collider
if(inventory.ContainsKey(keyDoor.GetItemType())) {////MY UNLOCKING PROCESS////}
So my problem is when I save, it returns the error cannot convert Item.ItemType to Item, which Ive read is trying to compare the enum Int value with the string of the actual item. So I thought hey try
public Item GetItemType(){
return itemType;
}
on the door, which did result in no errors but no working unlock. So I was wondering if you may lend some more insight on this dilema! Thanks for all the videos and congrats on your award!
@@MichaelHeist That should work, why is the unlocking not working? Seems like it's related to the unlock logic and not the identify key logic. Add some Debug.Log to see what your code is doing
@@CodeMonkeyUnity I know, I could have sworn it would have worked. As for the Debug it would return the word item, if it typed item.itemtype then I get the correct results, which was weird. For now I just went with a foreach loop on the get item list, when you enter the collider. Which does work but didn’t seem as efficient as just checking the one item. But I know I’ll revisit this issue when I go back and revise some things. Thank you once again for what you do.
thank you so much
For all the beginners, set the videospeed to 0.75 - thank me later ;)
Still way too fast but helped a little bit lol
it works perfectly but i was wondering how would i make a simple crafting system like when i want to make a building that needs 2 woods and 3 gold,if i have the required materials needed to build in my inventory , the materials gets used up from the inventory..
something like this..
how would i approach this?
I covered a crafting system here unitycodemonkey.com/video.php?v=E91NYvDqsy8
at 5:52 he is dropping the UI_inventory to the inspector. When I'm doing that part, it doesn't allow it. It only lists my Player as only reference available. What I am doing wrong? At times it's little hard to follow, because UI_inventory script and gameobject is named the same, so I'm not always sure which one the reference should apply to.
You have to add the UI_Inventory Script to the UI_Inventory gameObject aswell.
@@UnityJunkie dude you saved me. Thanks!
cool now I just need to find out how to make that spineless so I can throw it into my game without knowing which items will be there
help!!!, when I click, it does nothing, I already download and compare it but they are the same, the layouts, the inputs, everything, I already debug it and if it enters Button_UI but when it clicks it does not respond, please help!
Thx, God this is advance method for me .
Not quite what you did to make the pfItemWorld in the scene not be visible but allow the spawned clones to be visible?
Thank you
For the Universal Render Pipeline, is there a way to have a sprite block light? Ie: light not passing through a wall
how to save and load same inventory items if player close the game and come back again?
Look into some kind of Save System like this one unitycodemonkey.com/video.php?v=6uMFEM-napE
@@CodeMonkeyUnity cool thks