Simple Inventory System in Unity (Store, Use, Stack and Drop Items)

Поделиться
HTML-код
  • Опубликовано: 23 дек 2024

Комментарии • 1,2 тыс.

  • @CodeMonkeyUnity
    @CodeMonkeyUnity  5 лет назад +47

    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

    • @acp9477
      @acp9477 5 лет назад +2

      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.

    • @arcday4281
      @arcday4281 4 года назад

      ​@@acp9477Can you recommend anything ? We will be grateful )

    • @trankhanhmai6051
      @trankhanhmai6051 3 года назад

      "StackOverFlowException: the requested operation caused a stack overflow" Error
      Help me, I dont Understand why i have this error

    • @federicotamburini
      @federicotamburini 3 года назад

      Hi, i download your pkg, but it dont work for some reference miss... The Ligth2D is non fuond O.o

    • @deanroy1747
      @deanroy1747 3 года назад

      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!

  • @nicholaspitti8171
    @nicholaspitti8171 3 года назад +179

    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

  • @kempokid2142
    @kempokid2142 3 года назад +82

    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.

    • @bkan1610
      @bkan1610 12 дней назад

      can be made a loooot more simpler

  • @BornatoBTW
    @BornatoBTW Год назад +10

    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.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  Год назад +5

      I'm glad you found the video helpful! Best of luck with your project!

  • @rauchgal
    @rauchgal 2 года назад +38

    Whenever he says "and here its very simple.." , slow the video down to 0.25

  • @Astro-Drifter
    @Astro-Drifter 8 месяцев назад +4

    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
      @CodeMonkeyUnity  8 месяцев назад +2

      Nice! The devlogs have a really interesting style, best of luck with the game!

    • @Astro-Drifter
      @Astro-Drifter 7 месяцев назад

      @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 😁

  • @newgoogleaccount3526
    @newgoogleaccount3526 3 года назад +9

    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

  • @Chyllandra
    @Chyllandra 3 года назад +78

    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.

    • @Xerisis
      @Xerisis 3 года назад +2

      Had that same issue as both were being called in Awake, yet one wasn't ready yet.

    • @blazerburner38
      @blazerburner38 3 года назад +3

      I was having a problem and this fixed it, thanks!

    • @NotARealPersonBR
      @NotARealPersonBR 2 года назад +4

      dude, thanks so much, I was having problems with that

    • @ahm7edglahmed558
      @ahm7edglahmed558 Год назад

      thank you

    • @JorgeOsbaldo
      @JorgeOsbaldo Год назад +1

      I got crazy for 30 min looking for this error, thanks man!

  • @grayfoxgaming5691
    @grayfoxgaming5691 4 месяца назад +2

    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!

  • @tpglogin7410
    @tpglogin7410 4 года назад +48

    there is 2 types of people in the world:
    A: public void a() {
    }
    B: public void b()
    {
    }

    • @captainoblivious_yt
      @captainoblivious_yt 4 года назад +17

      B is the only acceptable one

    • @freakdenmator
      @freakdenmator 4 года назад +3

      @@captainoblivious_yt +1

    • @cyberguygame9096
      @cyberguygame9096 4 года назад +2

      @@captainoblivious_yt +7000000000 except Brackeys and CodeMonkey

    • @InvoRL
      @InvoRL Месяц назад +1

      @@captainoblivious_yt +

    • @marik996
      @marik996 13 часов назад

      B cuz its ez to read for me

  • @thelastremnant5333
    @thelastremnant5333 4 года назад +45

    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.

    • @FlatcapJ8080
      @FlatcapJ8080 4 года назад +4

      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.

    • @leviadams4488
      @leviadams4488 3 года назад +3

      your such a big help thank you i have spent like 2 hour troubleshooting this and sifting through the comments thank you so much

    • @ManamaEd
      @ManamaEd 3 года назад

      Fking love you for this

    • @abrar_C4boy
      @abrar_C4boy 2 года назад

      you save my dayy

    • @brurrik
      @brurrik 2 года назад

      Worked!!! Thanks!!

  • @MarushiaDark316
    @MarushiaDark316 3 года назад +16

    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.

    • @benharik5002
      @benharik5002 3 года назад +2

      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

    • @Matatoskr
      @Matatoskr 2 года назад

      so what changed for the TextMesh? I cant seem to change the text no matter what i do. NullReferenceException.

    • @y01cu_yt
      @y01cu_yt 2 года назад

      Agree, thanks.

    • @vilgotcoox3461
      @vilgotcoox3461 Год назад

      @@benharik5002 Thank you so much, took me like an hour to figure tis out.

  • @iamcat6610
    @iamcat6610 3 года назад +6

    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.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  3 года назад +3

      I'm glad the video helped you! Thanks!

    • @Ultratermin8or
      @Ultratermin8or 2 года назад +1

      how did you replace the sprite renderer in itemworld for 3D??

    • @Matatoskr
      @Matatoskr 2 года назад

      @@Ultratermin8or i THink u need to import 2D options to the 3d Unity

    • @dapizzaking4455
      @dapizzaking4455 2 года назад

      @@Ultratermin8or Instead of using a sprite renderer replace the function with Mesh. It works the same

    • @quinzelbeck
      @quinzelbeck 2 года назад

      @@dapizzaking4455 Whats the function, I understad that I need to change it, but I dont know how to write it :c

  • @oracleoftheavatar1883
    @oracleoftheavatar1883 3 года назад +14

    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 )

  • @feliperomano1286
    @feliperomano1286 3 года назад +11

    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. 😀

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  3 года назад +6

      It's all about experience! Just keep writing code and building systems and you will get there!

  • @cryo7180
    @cryo7180 4 года назад +15

    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

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 года назад +4

      It definitely takes quite a bit of time but I enjoy doing it!

    • @cryo7180
      @cryo7180 4 года назад +1

      @@CodeMonkeyUnity thank you for taking the time and effort ^.^ i wanted to know, will you ever give us tutorials on 3D games?

  • @denisedelbroek6320
    @denisedelbroek6320 2 года назад +6

    Me: Watches Tutorial, all looks good.
    CodeMonkeyUnity: *creates Inventory Interface at Super Speed*
    Me: even at 0.25 speed its to fast to follow...

  • @bishesh7209
    @bishesh7209 4 года назад +7

    It did help and saved my huge time for my project... Thank you so much!!

  • @intingido9751
    @intingido9751 4 месяца назад +1

    OMG I DID IT, only took me 7 days to follow this tutorial for my 3d game xD

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 месяца назад +1

      Nice! Great job on taking your time and really learning!

  • @stanislavamolnarova798
    @stanislavamolnarova798 11 дней назад +1

    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.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  8 дней назад +1

      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

  • @Paul32nd
    @Paul32nd 5 лет назад +42

    Can you stop stalking me xD
    I just wanted to start with the inventory system xD

    • @TheOfficialPolo
      @TheOfficialPolo 5 лет назад +2

      Every single time, huh? XD
      Literally same here

  • @blameyourm8519
    @blameyourm8519 2 года назад

    Question!!!
    5:33 Why do you make SetInventory( ) function? Why not directly assign variable inventory?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 года назад +2

      You should not make variables public and access from everywhere, doing that causes tons of issues unitycodemonkey.com/video.php?v=pD27YuJG3L8

    • @blameyourm8519
      @blameyourm8519 2 года назад

      @@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

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 года назад +1

      ​@@blameyourm8519 If you do that then you can't assign it while bypassing SetInventory();

  • @cuzimelliotcie9537
    @cuzimelliotcie9537 4 года назад +4

    Subscribed for the good quality tutorials
    and the the way of reveling the basics

  • @anonymoususer6664
    @anonymoususer6664 Год назад +1

    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

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  Год назад

      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

    • @steppingstone2688
      @steppingstone2688 Год назад +1

      You're an angel! Thank you!

    • @steppingstone2688
      @steppingstone2688 Год назад

      @@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!?".

  • @Grivendel1998
    @Grivendel1998 4 года назад +5

    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?

  • @childish_colors
    @childish_colors 4 месяца назад +1

    If you get object reference error at 16:40, Edit > Project settings > Script execution order > Add ItemAssets on top of the list.

    • @_At0mz
      @_At0mz 4 месяца назад +1

      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!

    • @childish_colors
      @childish_colors 4 месяца назад

      @@_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:).

  • @InfiniteCooper
    @InfiniteCooper 4 года назад +7

    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.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 года назад +3

      Yeah always be careful with regards to the actual size of the objects especially when dealing with Images that have lots of transparent pixels

  • @truanthh
    @truanthh Год назад +1

    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?

  • @nexy8966
    @nexy8966 4 года назад +3

    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.

    • @Varyian_Aspect
      @Varyian_Aspect 4 года назад

      Same here bro

    • @Varyian_Aspect
      @Varyian_Aspect 4 года назад +1

      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
      @CodeMonkeyUnity  4 года назад

      Find(); is case sensitive so the name must be exact. "image" is not the same as "Image"

    • @nexy8966
      @nexy8966 4 года назад

      @@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

  • @B4NTO
    @B4NTO 2 года назад +1

    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

  • @cecilialindgren6507
    @cecilialindgren6507 4 года назад +3

    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)

    • @ItsDurry
      @ItsDurry 3 года назад

      Hey 5 Months late to your comment. Did you ever find a solution I'm having this same problem

    • @jemamaook
      @jemamaook 3 года назад

      @@ItsDurry Same problem

    • @seanbingham6923
      @seanbingham6923 Год назад

      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.

  • @bunoholmesss
    @bunoholmesss 3 года назад +2

    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.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  3 года назад +1

      Use Debug.Log to find what is null ruclips.net/video/5irv30-bTJw/видео.html

    • @bunoholmesss
      @bunoholmesss 3 года назад +1

      @@CodeMonkeyUnity Thank you.

  • @benaffleck480
    @benaffleck480 3 года назад +8

    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?

    • @a_rockgames6019
      @a_rockgames6019 2 года назад +1

      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

  • @alivgalihpratama5126
    @alivgalihpratama5126 3 года назад +2

    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)

  • @Oxmond
    @Oxmond 4 года назад +3

    Great stuff! Thx! 👍🤓

  • @jogl7507
    @jogl7507 4 года назад +2

    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

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 года назад +1

      You have something set to null, use Debug.Log(); to find out what

    • @sloth6171
      @sloth6171 4 года назад

      I had the same error what seemed to fix it?

    • @jogl7507
      @jogl7507 4 года назад

      IM THE SLOTH I just restarted the tutorial and re wrote all the scripts and that made it work somehow

    • @gawer33
      @gawer33 4 года назад

      same error UIInventory.RefreshInventoryItems ()

  • @Wayloz
    @Wayloz 3 года назад +4

    You did great on this but the speed is a little frustrating to keep up with.

    • @Wayloz
      @Wayloz 2 года назад

      Coming back four months later to do it again and holy cow, applying this to VR is aggravating.

    • @JohnnyStambino
      @JohnnyStambino 2 года назад

      @@Wayloz this is an infuriating tutorial to follow. Im done, starting over with someone elses video

  • @JerryStano
    @JerryStano Год назад +2

    Love how you went x1000 speed when doing the background images for items was super easy to follow

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  Год назад

      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

    • @krzook5408
      @krzook5408 Год назад

      dont cry lol

  • @inkir3222
    @inkir3222 4 года назад +3

    how do i ask if an item is already in the inventory in an if() statement?

  • @eneaganh6319
    @eneaganh6319 Год назад

    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?

  • @ryana.9821
    @ryana.9821 4 года назад +5

    You are awesome! Thanks for doing this, your lessons have helped a lot of people achieve their goals :)

  • @Matatoskr
    @Matatoskr 2 года назад +1

    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?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 года назад +2

      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

    • @Matatoskr
      @Matatoskr 2 года назад +1

      @@CodeMonkeyUnity THANKS MAN! wtached your video. Narrowed down the problem and now its fixed thanks!

  • @toweringsequoias1590
    @toweringsequoias1590 4 года назад +4

    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

    • @toweringsequoias1590
      @toweringsequoias1590 4 года назад

      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)

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 года назад +1

      You have something set to null, use Debug.Log(); to figure out what it is.

    • @gawer33
      @gawer33 4 года назад +2

      @@toweringsequoias1590 i have same error how do you solve yours

    • @toweringsequoias1590
      @toweringsequoias1590 4 года назад

      @@CodeMonkeyUnity where would I put the debug.log line?
      still trynna figure it out >

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 года назад

      @@toweringsequoias1590 Wherever you have that error, add Debug.Log to see the value stored on whatever object you're trying to access.

  • @SayedSafwan
    @SayedSafwan Год назад

    Simply Amazing!

  • @timothymccune7047
    @timothymccune7047 5 лет назад +7

    Can you make a tutorial on how to equiped weapons from your inventory and one on how to craft items from your inventory pls.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  5 лет назад +13

      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.

  • @Surrendityy
    @Surrendityy 3 года назад +2

    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.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  3 года назад

      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?

    • @Surrendityy
      @Surrendityy 3 года назад

      @@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.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  3 года назад +1

      @@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.

  • @jameshamil
    @jameshamil 4 года назад +7

    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!

  • @chrismcintosh2286
    @chrismcintosh2286 2 года назад +2

    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

    • @CodeSpag
      @CodeSpag 2 года назад

      I'm trying to do the same thing, how did you link it all together ?

  • @ganasoft816
    @ganasoft816 5 лет назад +16

    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)

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  5 лет назад +10

      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.

    • @ganasoft816
      @ganasoft816 5 лет назад +5

      @@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!

  • @JustBaal
    @JustBaal Год назад

    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?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  Год назад +1

      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.

    • @JustBaal
      @JustBaal Год назад +1

      @@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 ❤️

  • @arish7231
    @arish7231 5 лет назад +3

    u teach so good 😍

  • @smy6177
    @smy6177 3 года назад +2

    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.

    • @UnityJunkie
      @UnityJunkie 3 года назад +1

      You have to add the UI_Inventory Script to the UI_Inventory gameObject aswell.

    • @towel3452
      @towel3452 2 года назад

      @@UnityJunkie dude you saved me. Thanks!

  • @logical29
    @logical29 3 года назад +6

    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?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  3 года назад +3

      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

    • @logical29
      @logical29 3 года назад +2

      Thank you so much for taking the time out to reply. It's greatly appreciated. Loving the tutorials. Keep it up!

  • @Alkudero
    @Alkudero 2 года назад +1

    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?

    • @Alkudero
      @Alkudero 2 года назад

      Nvm fixed it!

    • @quinzelbeck
      @quinzelbeck 2 года назад

      @@Alkudero how do you fix it?

    • @grayfoxgaming5691
      @grayfoxgaming5691 4 месяца назад +1

      @@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?

  • @saultraver
    @saultraver 3 года назад +7

    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 :(

    • @joshuadrewlow
      @joshuadrewlow 3 года назад +3

      I watch it in 0.25 speed, it's a messy workaround, but it works! 😆

  • @intingido9751
    @intingido9751 5 месяцев назад +2

    Me: stopping the video multiple times on 0.25x speed

  • @Kurokage130
    @Kurokage130 4 года назад +4

    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!

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 года назад +3

      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.

    • @Kurokage130
      @Kurokage130 4 года назад +1

      @@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.

    • @fck00_
      @fck00_ 4 года назад +1

      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

  • @kylehelmer3825
    @kylehelmer3825 5 месяцев назад

    Not quite what you did to make the pfItemWorld in the scene not be visible but allow the spawned clones to be visible?

  • @jasons5398
    @jasons5398 4 года назад +5

    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.

    • @zapdoezap5497
      @zapdoezap5497 4 года назад +5

      Thanks! From my player script I changed it from Awake to Start. Hopefully it doesn't cause any future issues!

    • @marvinanasco8201
      @marvinanasco8201 4 года назад

      Men It nothing's Happen

  • @darteco6507
    @darteco6507 2 года назад +1

    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

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 года назад

      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();

    • @hectoraquino3517
      @hectoraquino3517 2 года назад

      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.

  • @prod.storm3925
    @prod.storm3925 3 года назад +4

    For anyone asking, this script is outdated. I followed this 3 times line for line and I keep getting unexplained errors

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  3 года назад

      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.

    • @prod.storm3925
      @prod.storm3925 3 года назад

      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.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  3 года назад

      @@prod.storm3925 What null ref errors? Use Debug.Log to find out what is null ruclips.net/video/5irv30-bTJw/видео.html

    • @prod.storm3925
      @prod.storm3925 3 года назад

      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.

    • @prod.storm3925
      @prod.storm3925 3 года назад

      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

  • @matthewe.proteau6100
    @matthewe.proteau6100 3 года назад +1

    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

    • @jemamaook
      @jemamaook 3 года назад +1

      Same problem here

  • @loreAkira22
    @loreAkira22 4 года назад +3

    I find really difficult to follows your videos.
    It may depends by the fact that I am a beginner, and you skip a lot of explanations.
    I am looking videos for learn and not for copy your code, I would like to master the code so I can make it my own, and add the relative fix/adjustments.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 года назад +2

      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

    • @tortolgawd4481
      @tortolgawd4481 4 года назад +1

      yep pls code monkey learn to chill down

  • @kruth6663
    @kruth6663 Год назад

    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?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  Год назад +1

      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

    • @kruth6663
      @kruth6663 Год назад

      @@CodeMonkeyUnity Oh I see! I should read the documentation more carefully next time. Thank you so much for explaining! And so soon!

  • @mephisto95
    @mephisto95 2 года назад +4

    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
      @CodeMonkeyUnity  2 года назад

      What part can't you follow?

    • @mephisto95
      @mephisto95 2 года назад

      ​@@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".

    • @JohnnyStambino
      @JohnnyStambino 2 года назад

      @@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

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 года назад

      ​@@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"

  • @ManamaEd
    @ManamaEd 3 года назад

    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

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  3 года назад

      Sounds like you're using UI text instead of World text, they are two different types, both can work just beware of the difference

    • @ManamaEd
      @ManamaEd 3 года назад

      @@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

  • @LearnWithArjun
    @LearnWithArjun 2 года назад +8

    Can you please not speed the video up its so irritating to pause it and write code!

  • @SayedSafwan
    @SayedSafwan Год назад

    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?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  Год назад

      I covered a crafting system here unitycodemonkey.com/video.php?v=E91NYvDqsy8

  • @eliasmarnev
    @eliasmarnev 4 года назад +3

    how can this video have dislikes???

  • @luluskuy
    @luluskuy 6 месяцев назад

    8:36 that switch functions looking handy

  • @mehmetberkaycoruk4605
    @mehmetberkaycoruk4605 Год назад

    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?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  Год назад

      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

    • @mehmetberkaycoruk4605
      @mehmetberkaycoruk4605 Год назад

      @@CodeMonkeyUnity Thank you. You sir are someone special, trying to reply to every question... Happy to have someone like you!

  • @denisgoodman4492
    @denisgoodman4492 4 года назад +1

    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?

  • @rohlik0095
    @rohlik0095 3 года назад +2

    @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)

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  3 года назад +1

      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

    • @rohlik0095
      @rohlik0095 3 года назад

      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

    • @arick2050
      @arick2050 3 года назад

      @@rohlik0095 I had the same problem. All I did was reimport all my assets and it fixed the issue.

  • @coconut-nx5uk
    @coconut-nx5uk 3 года назад +2

    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

  • @gyrozeppeli5390
    @gyrozeppeli5390 3 года назад +1

    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.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  3 года назад

      Use Debug.Log to find what is null ruclips.net/video/5irv30-bTJw/видео.html

    • @gyrozeppeli5390
      @gyrozeppeli5390 3 года назад

      @@CodeMonkeyUnity yea i fixed it thanks

  • @brokenvessel8589
    @brokenvessel8589 4 года назад +2

    This works great! But how would I put a cap on the inventory size?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 года назад

      Before you add an item check if the list size has space

  • @gamedev.1166
    @gamedev.1166 5 лет назад +2

    Very nice!!

  • @Ashnaflavdjov
    @Ashnaflavdjov 2 года назад

    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

  • @schnek8927
    @schnek8927 2 года назад +1

    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...

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 года назад

      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?

    • @schnek8927
      @schnek8927 2 года назад

      @@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.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 года назад

      ​@@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

  • @koferperk
    @koferperk 3 года назад +1

    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);"?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  3 года назад +1

      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.

    • @koferperk
      @koferperk 3 года назад

      @@CodeMonkeyUnity why is ClickFunc() inside RefreshInventory() ?

    • @koferperk
      @koferperk 3 года назад

      also for this part 12:30, Whats the difference between using
      "private Action useItemAction;" and "private event Action useItemAction;"

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  3 года назад +1

      @@koferperk Adding the event keyword adds some limitations to keep your code more organized ruclips.net/video/OuZrhykVytg/видео.html

    • @koferperk
      @koferperk 3 года назад

      @@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;"

  • @jmaslaki
    @jmaslaki 15 дней назад

    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...

  • @thendar823
    @thendar823 2 года назад

    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)

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 года назад

      That's a C# event, I covered them in more detail here unitycodemonkey.com/video.php?v=OuZrhykVytg

  • @Etj1013
    @Etj1013 2 года назад +1

    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.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 года назад +1

      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

    • @Etj1013
      @Etj1013 2 года назад

      @@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.

  • @elcassette9612
    @elcassette9612 3 года назад +1

    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!

  • @firedanger226
    @firedanger226 4 года назад

    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!

  • @anotherone3641
    @anotherone3641 5 лет назад

    Thank u for advertising, bro! During your advertising, RUclips does not interrupt to another :)

  • @mertcanoz3330
    @mertcanoz3330 2 года назад

    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.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 года назад +1

      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

    • @mertcanoz3330
      @mertcanoz3330 2 года назад

      @@CodeMonkeyUnity Thank you so much its worked !

  • @glennhofmannl
    @glennhofmannl 4 года назад

    @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?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 года назад +1

      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

  • @WorldAquariumSingapore
    @WorldAquariumSingapore 2 года назад +1

    how to save and load same inventory items if player close the game and come back again?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 года назад +1

      Look into some kind of Save System like this one unitycodemonkey.com/video.php?v=6uMFEM-napE

    • @WorldAquariumSingapore
      @WorldAquariumSingapore 2 года назад +1

      @@CodeMonkeyUnity cool thks

  • @MichaelHeist
    @MichaelHeist 2 года назад

    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!!

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 года назад +1

      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.

    • @MichaelHeist
      @MichaelHeist 2 года назад

      @@CodeMonkeyUnity Awesome thanks for the quick reply, I’ll check this out!

    • @MichaelHeist
      @MichaelHeist 2 года назад

      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!

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 года назад +1

      @@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

    • @MichaelHeist
      @MichaelHeist 2 года назад

      @@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.

  • @WorldAquariumSingapore
    @WorldAquariumSingapore 2 года назад +1

    how to limit the inventory slots from growing at y non stop?

    • @WorldAquariumSingapore
      @WorldAquariumSingapore 2 года назад +1

      Ok i set it up for the y to stop growing within my total number of slots required and with in my background

  • @lucasserenteixeira7991
    @lucasserenteixeira7991 4 года назад +1

    Im stuck on 5:50, i have no idea why i can't drag the script to Ui Inventory field

    • @ismettahaarslan957
      @ismettahaarslan957 4 года назад

      It must have UI_Inventory script attacted to it

    • @lucasserenteixeira7991
      @lucasserenteixeira7991 4 года назад

      @@ismettahaarslan957 that's what i cant do

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 года назад

      Does the object you're trying to drag have the UI_Inventory script attached to it?

    • @lucasserenteixeira7991
      @lucasserenteixeira7991 4 года назад

      @@CodeMonkeyUnity im trying to attach the UI Inventory to the UI Inventory field***************
      (I typed it wrong before, sorry)

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 года назад

      @@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.

  • @ibi9682
    @ibi9682 3 года назад +1

    When it duplicates more icons are showing on the icon below the previous one HELP PLEASE!!

  • @antonjjohansson
    @antonjjohansson 2 года назад

    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.

  • @ozurisa
    @ozurisa 3 года назад +1

    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

    • @leviadams4488
      @leviadams4488 3 года назад

      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.

  • @ZeeshanKhan-ny8pm
    @ZeeshanKhan-ny8pm 4 года назад +2

    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

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 года назад

      Either itemSlotRectTransform is null or it doesn't have a child named "image"

    • @NEFxDEF
      @NEFxDEF 4 года назад +2

      @@CodeMonkeyUnity i think this is where my issue lies too, where before 9:12 did you make a child gameobject called "image"?

  • @walid.0001
    @walid.0001 2 года назад +2

    Thanks for all of your tutorials I've learned a lot of from you

    • @medievalfarmerstudio4762
      @medievalfarmerstudio4762 2 года назад +7

      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);
      }

    • @medievalfarmerstudio4762
      @medievalfarmerstudio4762 2 года назад

      also check my games on my YT channel :D ^^ huehuehue

    • @andrewvan-heerden359
      @andrewvan-heerden359 2 года назад +1

      @@medievalfarmerstudio4762 2 months down the line and this helped, so thank you

    • @lonar993
      @lonar993 2 года назад +1

      @@medievalfarmerstudio4762 Really thank you, you are a live saver

    • @ayberkkarakas6898
      @ayberkkarakas6898 Год назад

      @@medievalfarmerstudio4762 You are a freaking life saver!

  • @leviadams4488
    @leviadams4488 3 года назад

    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

  • @Zeftax
    @Zeftax 3 года назад +2

    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.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  3 года назад +2

      Thanks! I'm glad you found the video useful!

  • @marlomiller7873
    @marlomiller7873 3 года назад +1

    I have a Question about dropping the item when i type get position for the player position it does not work pls help

    • @Scr33chGaming
      @Scr33chGaming 3 года назад +1

      check your Player.cs, you should have this in there (sounds like its missing) :
      internal Vector3 GetPosition()

      {
      return transform.position;
      }