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!
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
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.
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.
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 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
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.
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!
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.
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
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 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 )
Hi I have a question, I'm a beginner at unity and I do not understand the inside of that for loop at 8:55 can anyone explain in detail? Thanks in advance.
It's cycling through all the items in the inventory, then using some basic math to position them according to their index in the inventory list. The Y increases after a certain X just to have items on multiple rows and not just one row. By the way check out the Loops lecture on my free C# course ruclips.net/video/qZpMX8Re_2Q/видео.html
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!?".
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?
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:).
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.
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?
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
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.
I have problem I'm at 7:40 minute of film an unity show me 2 problems 1:NullReferenceException: Object reference not set to an instance of an object UI_Inventory.Awake () 2:NullReferenceException: Object reference not set to an instance of an object playerMovement.Awake () Please help.
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 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)
I'm stuck at 9:10. Whenever i play i get NullReferenceException: Object reference not set to an instance of an object UIInventory.RefreshInventoryItems () (at Assets/Scripts/Inventory/UIInventory.cs:35) UIInventory.SetInventory (Inventory inventory) (at Assets/Scripts/Inventory/UIInventory.cs:20) PlayerMove.Start () (at Assets/Scripts/Player/PlayerMove.cs:30) I've tried and I can't seem to fix it
I cant seem to change the text to show the amount in the inventory. NullReferenceException, object reference not set to an instance, which doesnt make sense because it should be. I see other people saying its about the timing when we instantiate? but i dont know how to go about and fix it. ALSO!!!! 19:15 how does your textMeshPro work here. Arnt you trying to find the amountText in the object you instantiated? BUt you said find("text"). Is that something im misunderstanding?
Use Debug.Log to find what is null unitycodemonkey.com/video.php?v=5irv30-bTJw Yes you're right I think I might have noticed that mistake when compiling the code and then refactored it with the correct name but didn't include it in the video
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)
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.
Getting null references error in line uiInventory.setInventory(inventory) at 7:41 I debugged and checked uiinventory and it’s showing null. I dragged up inventory properly to serialized field uiInventory.
You dragged the reference but when you hit play it goes back to null? Are you destroying the UI object? Do you have anything else which is setting that field to null?
@@CodeMonkeyUnity even during play the object (ui inventory) is there in the inspector window. And I am not destroying it. Debug.log(uiInventory.name) is giving null references and therefore uiInventory.Setinventory command is not working.
@@Surrendityy Then either you didn't drag the reference in the editor or you have multiple instances of that script and you only assigned the reference in one of them.
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!
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'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!
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 ❤️
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.
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 ruclips.net/video/E91NYvDqsy8/видео.html
@@quinzelbeck I don't know if you ended up figuring it out, but I'm in the same boat. I don't understand, if you're going to comment that you've fixed it, why not explain or at least give a pointer in which that can help solve it for others?
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 :(
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
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.
I'm getting a null error, and I have no idea where the null is. When I run my game it says "ArgumentException: The Object you want to instantiate is null." (sorry, I'm new to game dev and don't know what this means) I get the error at this moment in the video 11:47
Use Debug.Log to find what is null unitycodemonkey.com/video.php?v=5irv30-bTJw From the message I would assume it's the reference you're passing into Instantiate();
same error with me.. I did everything you did.. and everything worked just fine. but after i restart unity the argumentException apear.. wth. I remade the code 3 times now just to be sure that that's what really happening. I think the source code is outdated or something.
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.
I'm unable to see the three potions at 7:40, im unsure if this is because my measurements are off or that i am using a rawimage for the icons. someone please halp
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 ruclips.net/p/PLzDRvYVwl53vxdAPq8OznBAdjf0eeiipT And then make Flappy Bird ruclips.net/video/b5Wpni9KPik/видео.html If you follow all that you will gain a nice knowledge base to draw from
Hi, at 10:49, on what occasion should you add the rotation parameter while instantiating a prefab, should you always add it? I think I don't always see it added on Instatiate(). I assumed when you don't add it, it would be equal to Quaternion.identity by default, would it not?
If you use the Instantiate() version with a spawn position you have to include rotation, there's no version of that function that just takes a spawn position Alternatively you can just use the version that takes a prefab, it will be spawned on the position and rotation stored on the prefab
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"
@@CodeMonkeyUnity For some reason the one you chose made the destroy(gameobject) not work anymore. I have no idea why and how that would affect it but yeah. I did get it to work by adding the canvas tho
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?
In 8:30 why does the "default" statement runs without issues? If you put it at the end it only works with "return null" added after it. Why did the compiler accept it as valid code without any statements present?
default works just like any other case, it "falls down" to the next case until it finds a break; You don't need to add a break for every single case, you can have multiple cases (including default) doing the same logic and hitting the same break point. You can put it at the end as long as you put a break after it
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?
@Code Monkey hey Im having litle problem with 9:13 and NullReference in the Item script, I wached your video about it and I know I should use the Debug.Log to fix the NullReference but I dont know where I shoud write it, maybe Im to stupid for this :) i would be so happy if someone can help me this is the error- NullReferenceException: Object reference not set to an instance of an object Item.GetSprite () (at Assets/Scripts/Item.cs:26) Ui_Inventory.RefreshInventoryItems () (at Assets/Scripts/Ui_Inventory.cs:37) Ui_Inventory.SetInventory (Inventory inventory) (at Assets/Scripts/Ui_Inventory.cs:22) PlayerHealth.Awake () (at Assets/Scripts/PlayerHealth.cs:28)
Look in that line and on the line before add the Debug.Log to find the value in the variables that you're using in that line ruclips.net/video/5irv30-bTJw/видео.html
Thanks for responding and for your help I really appreciate it, I manage to fix it in half because when I start my game it is not working (it writes null reference) but when my player dies and I press restart than it works fine everithing, no errors all items are displayed so idk :) ...and u have awesome tutorials
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
9:09 Nullreferenceexception Object reference not set to an jnstance of an objrct Item.GetSprite() at Assets/Scripts/Player/Inventory/Item I checked my code and inspector and I dont see the problem.
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
11:47 I get a NullReferenceException, because it wont let me set "Pf Item World" in the ItemAssets gameobject script. The prefab just isn't an option, no idea what i'm doing wrong :/b Been over the code multiple times and cannot find an error. I can place the prefab in the world, then it becomes available (as a scene option ofc), but playing only spawns a single item with the wrong sprite...
Use Debug.Log to find exactly what is null ruclips.net/video/5irv30-bTJw/видео.html The prefab reference shouldn't be cleared by itself, so maybe you're accidentally clearing it after spawning once?
@@CodeMonkeyUnity Hello again. So the prefab was easy to fix, just needed a restart and then i was suddenly able to reference it... Turns out that wasn't the error! D: Using a debug.log i found it's apparently 'inventory' in the player script that has a null reference. Still don't know why though. The error, "ArgumentException: object instantiate is null", tells me the error is at; *RectTransform itemSlotRectTransform = Instantiate(itemSlotTemplate, itemSlotContainer).GetComponent();* ... in ui inventory script under RefreshInventoryItems, then; *RefreshInventoryItems();* ... right above it, at SetInventory(Inventory inventory), and finally; *uiInventory.SetInventory(inventory);* ... in the player script. Please tell me i'm just missing something really obvious... x_x Btw, does your player script contain anything that this tutorial needs to function? I'm using a completely different form of movement and player, so maybe i'm missing something crucial, unless that doesn't matter and the other code in the player script has nothing to do with it.
QUESTION: Why is: itemSlotRectTransform.GetComponent().ClickFunc = () => { //Use Item }; Put in the RefreshFunction? and not the update function. I'm confused 24:44 Also I am a noob so I never seen this " inventory = new Inventory(UseItem);" with UseItem being a method. I thought you had to set it like this " inventory = new Inventory(UseItem());" . Can someone explain "inventory = new Inventory(UseItem);"?
The ClickFunc delegate is triggered when the click happens, no need to set it on every update, just once. I covered delegates in detail here ruclips.net/video/3ZfwqWl-YI0/видео.html Same thing for your second question, the parameter the constructor takes is a Action Delegate which means it receives a function.
@@CodeMonkeyUnity That makes a lot of sense :O. So what was the limitation in the case of: "private Action useItemAction;" and not "private event Action useItemAction;"
Is there any way you can tweak this to select the inventory items with arrow keys, I don't know how to access or store the list of items as gameObjects. Like the item slots as gameObjects...
14:10 How did this "subscribe" thing work? I had to write it out all by myself and at first didnt even notice that I was missing it (obv didnt work without)
hi Code Monkey, question if I may. I'm drawing a blank on what it's called when you combine different items in an inventory to make something completely new. For example, I have a wooden stick and a sharp piece of metal in the inventory and I combine them to make a spear.
Crafting? Merging? Don't think there's a universal term for that, each game calls it something different. I made a Minecraft-like crafting system here unitycodemonkey.com/video.php?v=E91NYvDqsy8
@@CodeMonkeyUnity oh dang, I wasn't expecting the Code Monkey himself to respond 😳 (I bought your udemy course on bolt, bloody love it mate). Crafting is the word I was looking for, you actually did a video on it. Thank you so much man, you rock.
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!
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!
Hi thanks for your Lesson first of all ! But I wonder that in 5:52 how do you attach the UI_Invertoy gameObject as an UI_Invertory Class Type ? I cant drag this GameObject to script's SerializeField area because they are different Types.
@26:13 i'm getting the following error: Assets\Scripts\Player.cs(53,60): error CS0120: An object reference is required for the non-static field, method, or property 'Item.itemType' and Assets\Scripts\Player.cs(53,60): error CS0176: Member 'Item.ItemType.Gold' cannot be accessed with an instance reference; qualify it with a type name instead private void UseItem(Item item) { switch (item.itemType) { case Item.ItemType.Gold: Debug.Log("clicked gold!"); inventory.RemoveItem(new Item { itemType = Item.itemType.Gold, amount = 1 }); break; default: break; } } Any idea what's going on here?
You are using "Item.itemType.Gold" and "Item.ItemType.Gold" What is the exact name of the enum type? Did you define it as ItemType or itemType? One of those is wrong
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 ruclips.net/video/tJ_ycboPFmY/видео.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.
@@lucasserenteixeira7991 Yes I understand and the only reason why that would not work is if the object you're trying to drag does not have the UI_Inventory script attached to it.
7:10 I am having problems with my RefreshInventoryItem() fuction, saying that the x and y in the if (x > 4) statement are both "unnecessary value assignment", and when I start my game, I can see 3 sloths appearing in my hierarchy, but they don't line up next to each other, but stack onto each other. UPDATE: I just moved the x & y ints out of the function and made them public, seemed to fix the issue.
I got a problem with 11:47, when i got 3 Healing potion instantiate instead sword/mana, how can I fix that ? I got this problem because i drag the prefab pfItemWorld into ItemAsset script component, but if I did not drag it, i will get the variable pfItemWolrd of ItemAsset has not been assigned instead, please help me out, i nearly the day of due the assignmet
I have the same problem right now have you managed to fix it if you have please let me know thanks Edit: TheLast Remnant said this it might also help you 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.
please help me i am trying this from 3 days but can not solve this problem it gives error on this line Image image = itemSlotRectTransform.Find("image").GetComponent(); NullReferenceException: Object reference not set to an instance of an object
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.
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!
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?
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.
can be made a loooot more simpler
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!
Whenever he says "and here its very simple.." , slow the video down to 0.25
LOL TRUEEEE.
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 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
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!
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!
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 +
B cuz its ez to read for me
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!!
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.
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
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 )
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 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?
Me: Watches Tutorial, all looks good.
CodeMonkeyUnity: *creates Inventory Interface at Super Speed*
Me: even at 0.25 speed its to fast to follow...
It did help and saved my huge time for my project... Thank you so much!!
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!
Hi I have a question, I'm a beginner at unity and
I do not understand the inside of that for loop at 8:55 can anyone explain
in detail?
Thanks in advance.
It's cycling through all the items in the inventory, then using some basic math to position them according to their index in the inventory list. The Y increases after a certain X just to have items on multiple rows and not just one row.
By the way check out the Loops lecture on my free C# course ruclips.net/video/qZpMX8Re_2Q/видео.html
Can you stop stalking me xD
I just wanted to start with the inventory system xD
Every single time, huh? XD
Literally same here
Question!!!
5:33 Why do you make SetInventory( ) function? Why not directly assign variable inventory?
You should not make variables public and access from everywhere, doing that causes tons of issues unitycodemonkey.com/video.php?v=pD27YuJG3L8
@@CodeMonkeyUnity I see, but can't you just in this case make variable with {get; and private set;}, so now you can't cange it
@@blameyourm8519 If you do that then you can't assign it while bypassing SetInventory();
Subscribed for the good quality tutorials
and the the way of reveling the basics
Thanks!
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!?".
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?
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:).
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
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?
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
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
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.
I have problem I'm at 7:40 minute of film an unity show me 2 problems
1:NullReferenceException: Object reference not set to an instance of an object
UI_Inventory.Awake ()
2:NullReferenceException: Object reference not set to an instance of an object
playerMovement.Awake ()
Please help.
Use Debug.Log to find what is null ruclips.net/video/5irv30-bTJw/видео.html
@@CodeMonkeyUnity Thank you.
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 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)
Great stuff! Thx! 👍🤓
I'm stuck at 9:10. Whenever i play i get NullReferenceException: Object reference not set to an instance of an object
UIInventory.RefreshInventoryItems () (at Assets/Scripts/Inventory/UIInventory.cs:35)
UIInventory.SetInventory (Inventory inventory) (at Assets/Scripts/Inventory/UIInventory.cs:20)
PlayerMove.Start () (at Assets/Scripts/Player/PlayerMove.cs:30)
I've tried and I can't seem to fix it
You have something set to null, use Debug.Log(); to find out what
I had the same error what seemed to fix it?
IM THE SLOTH I just restarted the tutorial and re wrote all the scripts and that made it work somehow
same error UIInventory.RefreshInventoryItems ()
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
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
how do i ask if an item is already in the inventory in an if() statement?
6:20
Wouldn't it be better here to serializefield the i item slot container and template so we don't have to mess with strings?
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 cant seem to change the text to show the amount in the inventory. NullReferenceException, object reference not set to an instance, which doesnt make sense because it should be. I see other people saying its about the timing when we instantiate?
but i dont know how to go about and fix it. ALSO!!!!
19:15 how does your textMeshPro work here. Arnt you trying to find the amountText in the object you instantiated? BUt you said find("text"). Is that something im misunderstanding?
Use Debug.Log to find what is null unitycodemonkey.com/video.php?v=5irv30-bTJw
Yes you're right I think I might have noticed that mistake when compiling the code and then refactored it with the correct name but didn't include it in the video
@@CodeMonkeyUnity THANKS MAN! wtached your video. Narrowed down the problem and now its fixed thanks!
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.
Simply Amazing!
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.
Getting null references error in line uiInventory.setInventory(inventory) at 7:41 I debugged and checked uiinventory and it’s showing null. I dragged up inventory properly to serialized field uiInventory.
You dragged the reference but when you hit play it goes back to null? Are you destroying the UI object? Do you have anything else which is setting that field to null?
@@CodeMonkeyUnity even during play the object (ui inventory) is there in the inspector window. And I am not destroying it. Debug.log(uiInventory.name) is giving null references and therefore uiInventory.Setinventory command is not working.
@@Surrendityy Then either you didn't drag the reference in the editor or you have multiple instances of that script and you only assigned the reference in one of them.
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!
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 ?
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!
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 ❤️
u teach so good 😍
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!
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 ruclips.net/video/E91NYvDqsy8/видео.html
Thank you so much for taking the time out to reply. It's greatly appreciated. Loving the tutorials. Keep it up!
Awesome tutorial so far but at 7:42 my items just stack on top of each other instead of sorting in a grid! Can anynone help?
Nvm fixed it!
@@Alkudero how do you fix it?
@@quinzelbeck I don't know if you ended up figuring it out, but I'm in the same boat. I don't understand, if you're going to comment that you've fixed it, why not explain or at least give a pointer in which that can help solve it for others?
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! 😆
Me: stopping the video multiple times on 0.25x speed
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
Not quite what you did to make the pfItemWorld in the scene not be visible but allow the spawned clones to be visible?
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
I'm getting a null error, and I have no idea where the null is. When I run my game it says "ArgumentException: The Object you want to instantiate is null."
(sorry, I'm new to game dev and don't know what this means) I get the error at this moment in the video 11:47
Use Debug.Log to find what is null unitycodemonkey.com/video.php?v=5irv30-bTJw
From the message I would assume it's the reference you're passing into Instantiate();
same error with me.. I did everything you did.. and everything worked just fine. but after i restart unity the argumentException apear.. wth. I remade the code 3 times now just to be sure that that's what really happening. I think the source code is outdated or something.
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 ruclips.net/video/5irv30-bTJw/видео.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
I'm unable to see the three potions at 7:40, im unsure if this is because my measurements are off or that i am using a rawimage for the icons. someone please halp
Same problem here
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 ruclips.net/p/PLzDRvYVwl53vxdAPq8OznBAdjf0eeiipT
And then make Flappy Bird ruclips.net/video/b5Wpni9KPik/видео.html
If you follow all that you will gain a nice knowledge base to draw from
yep pls code monkey learn to chill down
Hi, at 10:49, on what occasion should you add the rotation parameter while instantiating a prefab, should you always add it? I think I don't always see it added on Instatiate(). I assumed when you don't add it, it would be equal to Quaternion.identity by default, would it not?
If you use the Instantiate() version with a spawn position you have to include rotation, there's no version of that function that just takes a spawn position
Alternatively you can just use the version that takes a prefab, it will be spawned on the position and rotation stored on the prefab
@@CodeMonkeyUnity Oh I see! I should read the documentation more carefully next time. Thank you so much for explaining! And so soon!
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"
If at 20:20 Your Text from the prefab doesn't show up in the game. Go to the prefab, and add component canvas. That fixed it for me
Sounds like you're using UI text instead of World text, they are two different types, both can work just beware of the difference
@@CodeMonkeyUnity For some reason the one you chose made the destroy(gameobject) not work anymore. I have no idea why and how that would affect it but yeah. I did get it to work by adding the canvas tho
Can you please not speed the video up its so irritating to pause it and write code!
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
how can this video have dislikes???
8:36 that switch functions looking handy
In 8:30 why does the "default" statement runs without issues?
If you put it at the end it only works with "return null" added after it. Why did the compiler accept it as valid code without any statements present?
default works just like any other case, it "falls down" to the next case until it finds a break; You don't need to add a break for every single case, you can have multiple cases (including default) doing the same logic and hitting the same break point.
You can put it at the end as long as you put a break after it
@@CodeMonkeyUnity Thank you. You sir are someone special, trying to reply to every question... Happy to have someone like you!
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?
@Code Monkey hey Im having litle problem with 9:13 and NullReference in the Item script, I wached your video about it and I know I should use the Debug.Log to fix the NullReference but I dont know where I shoud write it, maybe Im to stupid for this :) i would be so happy if someone can help me
this is the error- NullReferenceException: Object reference not set to an instance of an object
Item.GetSprite () (at Assets/Scripts/Item.cs:26)
Ui_Inventory.RefreshInventoryItems () (at Assets/Scripts/Ui_Inventory.cs:37)
Ui_Inventory.SetInventory (Inventory inventory) (at Assets/Scripts/Ui_Inventory.cs:22)
PlayerHealth.Awake () (at Assets/Scripts/PlayerHealth.cs:28)
Look in that line and on the line before add the Debug.Log to find the value in the variables that you're using in that line ruclips.net/video/5irv30-bTJw/видео.html
Thanks for responding and for your help I really appreciate it, I manage to fix it in half because when I start my game it is not working (it writes null reference) but when my player dies and I press restart than it works fine everithing, no errors all items are displayed so idk :) ...and u have awesome tutorials
@@rohlik0095 I had the same problem. All I did was reimport all my assets and it fixed the issue.
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
9:09 Nullreferenceexception Object reference not set to an jnstance of an objrct Item.GetSprite() at Assets/Scripts/Player/Inventory/Item
I checked my code and inspector and I dont see the problem.
Use Debug.Log to find what is null ruclips.net/video/5irv30-bTJw/видео.html
@@CodeMonkeyUnity yea i fixed it thanks
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
Very nice!!
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
11:47 I get a NullReferenceException, because it wont let me set "Pf Item World" in the ItemAssets gameobject script. The prefab just isn't an option, no idea what i'm doing wrong :/b
Been over the code multiple times and cannot find an error.
I can place the prefab in the world, then it becomes available (as a scene option ofc), but playing only spawns a single item with the wrong sprite...
Use Debug.Log to find exactly what is null ruclips.net/video/5irv30-bTJw/видео.html
The prefab reference shouldn't be cleared by itself, so maybe you're accidentally clearing it after spawning once?
@@CodeMonkeyUnity Hello again. So the prefab was easy to fix, just needed a restart and then i was suddenly able to reference it...
Turns out that wasn't the error! D:
Using a debug.log i found it's apparently 'inventory' in the player script that has a null reference. Still don't know why though.
The error, "ArgumentException: object instantiate is null", tells me the error is at;
*RectTransform itemSlotRectTransform = Instantiate(itemSlotTemplate, itemSlotContainer).GetComponent();*
... in ui inventory script under RefreshInventoryItems, then;
*RefreshInventoryItems();*
... right above it, at SetInventory(Inventory inventory), and finally;
*uiInventory.SetInventory(inventory);*
... in the player script.
Please tell me i'm just missing something really obvious... x_x
Btw, does your player script contain anything that this tutorial needs to function?
I'm using a completely different form of movement and player, so maybe i'm missing something crucial, unless that doesn't matter and the other code in the player script has nothing to do with it.
@@schnek8927 You need to create the Inventory object and get it on the UI script, looks like you're never creating it so it stays as null
QUESTION: Why is:
itemSlotRectTransform.GetComponent().ClickFunc = () =>
{
//Use Item
};
Put in the RefreshFunction? and not the update function. I'm confused 24:44
Also I am a noob so I never seen this " inventory = new Inventory(UseItem);" with UseItem being a method. I thought you had to set it like this " inventory = new Inventory(UseItem());" . Can someone explain "inventory = new Inventory(UseItem);"?
The ClickFunc delegate is triggered when the click happens, no need to set it on every update, just once.
I covered delegates in detail here ruclips.net/video/3ZfwqWl-YI0/видео.html
Same thing for your second question, the parameter the constructor takes is a Action Delegate which means it receives a function.
@@CodeMonkeyUnity why is ClickFunc() inside RefreshInventory() ?
also for this part 12:30, Whats the difference between using
"private Action useItemAction;" and "private event Action useItemAction;"
@@koferperk Adding the event keyword adds some limitations to keep your code more organized ruclips.net/video/OuZrhykVytg/видео.html
@@CodeMonkeyUnity That makes a lot of sense :O. So what was the limitation in the case of: "private Action useItemAction;" and not "private event Action useItemAction;"
Is there any way you can tweak this to select the inventory items with arrow keys, I don't know how to access or store the list of items as gameObjects. Like the item slots as gameObjects...
14:10 How did this "subscribe" thing work? I had to write it out all by myself and at first didnt even notice that I was missing it (obv didnt work without)
That's a C# event, I covered them in more detail here unitycodemonkey.com/video.php?v=OuZrhykVytg
hi Code Monkey, question if I may. I'm drawing a blank on what it's called when you combine different items in an inventory to make something completely new. For example, I have a wooden stick and a sharp piece of metal in the inventory and I combine them to make a spear.
Crafting? Merging? Don't think there's a universal term for that, each game calls it something different.
I made a Minecraft-like crafting system here unitycodemonkey.com/video.php?v=E91NYvDqsy8
@@CodeMonkeyUnity oh dang, I wasn't expecting the Code Monkey himself to respond 😳 (I bought your udemy course on bolt, bloody love it mate).
Crafting is the word I was looking for, you actually did a video on it. Thank you so much man, you rock.
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!
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!
Thank u for advertising, bro! During your advertising, RUclips does not interrupt to another :)
Hi thanks for your Lesson first of all !
But I wonder that in 5:52 how do you attach the UI_Invertoy gameObject as an UI_Invertory Class Type ?
I cant drag this GameObject to script's SerializeField area because they are different Types.
Make sure you attach that script to that game object, if you do then you will be able to drag the game object to the field
@@CodeMonkeyUnity Thank you so much its worked !
@26:13 i'm getting the following error:
Assets\Scripts\Player.cs(53,60): error CS0120: An object reference is required for the non-static field, method, or property 'Item.itemType'
and
Assets\Scripts\Player.cs(53,60): error CS0176: Member 'Item.ItemType.Gold' cannot be accessed with an instance reference; qualify it with a type name instead
private void UseItem(Item item)
{
switch (item.itemType)
{
case Item.ItemType.Gold:
Debug.Log("clicked gold!");
inventory.RemoveItem(new Item { itemType = Item.itemType.Gold, amount = 1 });
break;
default:
break;
}
}
Any idea what's going on here?
You are using "Item.itemType.Gold" and "Item.ItemType.Gold"
What is the exact name of the enum type? Did you define it as ItemType or itemType? One of those is wrong
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
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 ruclips.net/video/tJ_ycboPFmY/видео.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.
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
Im stuck on 5:50, i have no idea why i can't drag the script to Ui Inventory field
It must have UI_Inventory script attacted to it
@@ismettahaarslan957 that's what i cant do
Does the object you're trying to drag have the UI_Inventory script attached to it?
@@CodeMonkeyUnity im trying to attach the UI Inventory to the UI Inventory field***************
(I typed it wrong before, sorry)
@@lucasserenteixeira7991 Yes I understand and the only reason why that would not work is if the object you're trying to drag does not have the UI_Inventory script attached to it.
When it duplicates more icons are showing on the icon below the previous one HELP PLEASE!!
7:10 I am having problems with my RefreshInventoryItem() fuction, saying that the x and y in the if (x > 4) statement are both "unnecessary value assignment", and when I start my game, I can see 3 sloths appearing in my hierarchy, but they don't line up next to each other, but stack onto each other.
UPDATE: I just moved the x & y ints out of the function and made them public, seemed to fix the issue.
tysm for this
I got a problem with 11:47, when i got 3 Healing potion instantiate instead sword/mana, how can I fix that ? I got this problem because i drag the prefab pfItemWorld into ItemAsset script component, but if I did not drag it, i will get the variable pfItemWolrd of ItemAsset has not been assigned instead, please help me out, i nearly the day of due the assignmet
I have the same problem right now have you managed to fix it if you have please let me know thanks
Edit:
TheLast Remnant said this it might also help you
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.
please help me i am trying this from 3 days but can not solve this problem it gives error on this line
Image image = itemSlotRectTransform.Find("image").GetComponent();
NullReferenceException: Object reference not set to an instance of an object
Either itemSlotRectTransform is null or it doesn't have a child named "image"
@@CodeMonkeyUnity i think this is where my issue lies too, where before 9:12 did you make a child gameobject called "image"?
Thanks for all of your tutorials I've learned a lot of from you
instead of
private void Awake()
{
ItemWorld.SpawnItemWorld(transform.position, item);
Destroy(gameObject);
}
Do it in start
private void Start()
{
ItemWorld.SpawnItemWorld(transform.position, item);
Destroy(gameObject);
}
also check my games on my YT channel :D ^^ huehuehue
@@medievalfarmerstudio4762 2 months down the line and this helped, so thank you
@@medievalfarmerstudio4762 Really thank you, you are a live saver
@@medievalfarmerstudio4762 You are a freaking life saver!
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
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!
I have a Question about dropping the item when i type get position for the player position it does not work pls help
check your Player.cs, you should have this in there (sounds like its missing) :
internal Vector3 GetPosition()
{
return transform.position;
}