Unity3D - Item Buffs/Stats | Scriptable Object Inventory System | Part 3

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

Комментарии • 264

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

    These tutorials are great for beginners. But, for someone who is just trying to find a good system to implement into their game, there are too many inconsistencies between videos. In order to understand one you have to watch everything. It doesn't help that only the results of part 5 are saved in the github repo. Also the naming scheme is a bit confusing. But that could just be me.

  • @daumantassimkus8611
    @daumantassimkus8611 4 года назад +56

    You can put your items in GridLayout then all those variables like X_SPACE_BETWEEN_ITEMS won't be necessary because GridLayout will do it automatically

  • @lukeplays7485
    @lukeplays7485 Год назад +7

    13:37
    ArgumentException: GetComponent requires that the requested component 'Image' derives from MonoBehaviour or Component or is an interface.
    Solution (In my case):
    Inside DisplayInventory, Remove: *using UnityEngine.UIElements;*
    and replace with: *using UnityEngine.UI;*
    Hope it helps.

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

      Thank you so much, i wrote using UnityEngine.UIElements; because he first had this on the screen and had an error because of it. Thanks for saving me!

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

      Amazing! Thank you! ⭐

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

      god

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

      Vielen Dank!
      Mir ist ein Stein vom Herzen gefallen, als ich aus voller Verzweiflung raus dein wunderschönen Kommentar gelesen & umgesetzt habe. Es funktioniert endlich!
      Ich hatte Angst, dass ich das Tutorial zum 3 Mal neu anfangen muss, weil irgend etwas nicht funktioniert.
      Vielen herzlichen Dank, du hast mich gerettet!

    • @Golem1988
      @Golem1988 11 месяцев назад

      Thank you very much!

  • @ftmining1473
    @ftmining1473 4 года назад +60

    Tip: If you are ever renaming anything in code just double click the line you want to rename, double tap ctrl + R and it will then highlight a green box around it, just rename it and it will auto rename everything to that new name, I mean everything, like it can be a separate script and it will still auto rename with that

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

      You sir, have made my life a thousand times easier.

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

      you can do a similar thing with control+f2, but its localised to a single script

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

    I've been learning Unity for 2 months and this is by far the hardest thing I've done. It all works fine, but I have to admit I was just parroting the code after a certain point without really grasping. I wish I understood it better so I could really put this info to use, but as least I understand what Scriptable Objects do now, and at least my inventory works I guess. Thanks for making all this info available , it's pretty awesome to have such good resources out here for free.

    • @CodingWithUnity
      @CodingWithUnity  4 года назад +11

      Atleast you got it working :,)

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

      i know i'm 7 months late on this, but i find a good way to learn is to start again in a new project (so you keep the original) and go through it again, then delete and go again and repeat while slowly learning a bit more each time you do it i't kind of like tracing, tracing is good as it teaches muscle memory that you then learn to use to create your own.
      and the more you trace the same thing the more you understand it and can eventually draw it without tracing.

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

      There are pretty serious problems with this series and I don't think it's on you or even the problem of creating a feature-complete inventory (which does seem like a surprisingly tall order for such a common game feature- I couldn't figure it out on my own and I ended up here as well), because this guide is full of spaghetti code and looking at the source code on the git it never gets any better. One line in DisplayInventory takes you through four different scripts and five different classes, bouncing you back and forth between two of those classes twice. It just isn't laid out well or in a way that makes sense so naturally you're going to end up following the motions without understanding why when in the span of three seconds he incorrectly reads off his own code and arrives at something that touches on three different pieces of code that each also referenced different scripts than the places where they were written.
      Not to mention a large portion of this video is spent undoing everything from the previous video and implementing a binaryformatter, a default C# feature that is "not secure and cannot be made secure," as a method to save and load game data, which is a terrible idea. Apart from just how convoluted this whole thing has been up to this point that is what made me decide to delete everything to do with this inventory system and start over from scratch. Only took a couple of minutes to patch up the issues this caused in my project even though I foolishly didn't make a backup before starting this, and while I'm sure it'll take a while starting over from scratch, it'll probably still be a lot faster than finishing this video series.

    • @eatower2
      @eatower2 14 дней назад

      @@vitriolicAmaranth I'll take "Useless Comments for 500", Alex.

  • @変態_豚野郎
    @変態_豚野郎 2 года назад +9

    Thank you so much for always uploading such helpful videos!
    The code worked so well that once I restarted Unity I got the following error:
    ■error:
    NullReferenceException: Object reference not set to an instance of an object
    DisplayInventory.UpdateDisplay () (at Assets/DisplayInventory.cs:46)
    (obj.transform.GetChild(0).GetComponentInChildren().sprite = inventory.database.GetItem[slot.item.Id].uiDisplay;)
    ■solution:
    "database" in "PlayerInventory" was lost, so I re-assigned it.
    Then error is recovered.
    It's something that will be solved as soon as I calm down and think about it.
    However, because of the huge number of sprites generated, my mind was in a panic last night.

  • @danielstatler954
    @danielstatler954 3 года назад +5

    PLEASE HELP. for some reason the display line of code in the inventory ui update script causes unity to instatiate inventoryPrefab every frame and it keeps saying variable display o defaultObject doesnt exist anymore. the defaultobject script takes me to the image script and idk what im doing wrong

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

      Did you solve this problem?

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

    Its hard to follow a tutorial where 80% of the code is being rewritten episode to episode.

  • @user-gj4yg9bk5o
    @user-gj4yg9bk5o 4 года назад +10

    So happy I found your channel - it's really a hidden gem here on RUclips, in the Unity space. I look forward to watching all of your videos!

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

    I'm glad I found your channel ! As a unity beginner struggling at keeping the code modular and organized, I really like your way of coding

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

    So I'm having an issue where my database gets cleared out in the player inventory every time I press play. I can click on the None (Item Database Object) field but and my database will show up. I select the database, but then it immediately goes back to none when I hit play. I've set my database to public (obviously) but I wasn't sure if I was missing anything else. I noticed that it wasn't doing that in your script...

  • @ana-zp7er
    @ana-zp7er 4 месяца назад +1

    Hi, help?
    my inventory just spawns non stopping inventoryPrefab as soons as I collide to some object... and gives this error too: KeyNotFoundException: The given key '0' was not present in the dictionary.
    System.Collections.Generic.Dictionary`2[TKey,TValue].get_Item (TKey key)

    • @thewiredspider9660
      @thewiredspider9660 Месяц назад

      Hi, so I had this issue the ID on one of my scriptable objects somehow got reset. So I had two items that both had ID of 0, I went and manually reset it, and it fixed it!

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

    i am lost .

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

    how to fix this problem
    KeyNotFoundException: The given key was not present in the dictionary.
    System.Collections.Generic.Dictionary`2[TKey,TValue].get_Item (TKey key) (at :0)
    DisplayInventory.UpdatDisplay () (at Assets/Scripte/Inventory/DisplayInventory.cs:38)
    DisplayInventory.Update () (at Assets/Scripte/Inventory/DisplayInventory.cs:24)

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

      Hard to say, sounds like you have a link not connected on one of the objects in the editor tho possibly maybe
      The error is pretty much saying your pulling an item from the database that isnt in the database

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

      ​ Coding With Unity I fix the problem, I Have been using an Image for display the inventory, and I replace it with the panel and that fixed the problem, You Are my favorite unity tutorials channel in the world +respect + sub.

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

      @@Cash_Online I'm getting this same error, what is the difference between a panel and a image? I believe they are pretty much the same.

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

      @@Vthoen I had the same problem. In the CreateDisplay() and UpdateDisplay () methods, I changed GetComponentInChildren to GetComponent. It helped me

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

    can anyone tell me how to set it so A: the values aren't random and B: none of the items stack?

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

    I don't normally comment on any of these tutorial videos but I just wanted to say that your videos on Scriptable Objects and inventory creation are amazing. They have helped me understand why Scriptable Objects are important and how to use them. This is also my absolute favorite inventory tutorial for just how in depth you go about everything and how you explain why you're doing things. Thank you for your hard work.

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

    Total unrelated but that ContextMenu attribute trick for calling functions in the editor blew my mind

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

    FINILY AFTER ONE YEAR I FIXED IT!!!!!

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

    Waiting for the equipment system *hyped* good video 👌

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

      Wont be long! I already have the majority of it coded, just have to make the UI and record the footage! (i probably will do the items bending with player animation after the equipment screen video, cause its a whole pipeline to do that)

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

    I've been a Unity user for around 10 years and this is the most helpful channel. I unfortunately JUST found it, and it has me thinking of revisiting an old unfinished project and reworking the entire loot system. Cheers mate! Keep up the great work!

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

    For anyone having issues with item ID zero, white sprites, and similar issues:
    Remember to drag new items to the Database object in the Resources folder

    • @DesignMade-Easy
      @DesignMade-Easy Год назад

      i did but some how im getting this error:
      NullReferenceException: Object reference not set to an instance of an object
      DisplayInventory.UpdateDisplay () (at Assets/DisplayInventory.cs:56)
      DisplayInventory.Update () (at Assets/DisplayInventory.cs:26)
      on this :
      obj.transform.GetChild(0).GetComponentInChildren().sprite = inventory.database.GetItem[slot.item.Id].uiDisplay;
      its also infinitely generating the prefab while say that error any ideas ?

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

      @@DesignMade-Easy Under Player Inventory you need to drag and drop the Database scriptable object

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

    I fixed my .GetChild(0).GetComponentInChildren() error by deleting using UnityEngine.UIElements and i kept only the using UnityEngine.UI;
    Unity was confused......
    Really good tutorial! Thx

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

    Gotta say, you are one of the better Unity/C# tut RUclipsr i have found so far. your way of coding is simple to understand and still very much leaning, the way you approach things
    makes it very easy to follow
    So keep up the great work
    Major Thumps up from here
    and of cause a sub aswell :)

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

      Thanks a lot for the compliment and the sub! I noticed a lot of people seemed to just code a completed script from top to bottom in their tutorials instead of working through it in a natural way, so i try to avoid doing that!

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

    First video was fantastic, this video was also very informative, but in doing it Unity deleted a bunch of the items I had set up.

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

    Could you please tell me what exactly do i need to change for getting the attributes only on the equipmentobject instead of all?

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

    About halfway through I kept getting an error that you weren't getting. I scratched my head and got very frustrated, ended up giving up for the day. Next day, I started up again with renewed vigour and low and behold it was all working! ~Have you tried turning it off and on again?~

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

      hahaha glad to see you got it working! Ill try to start separating the source code out per video, so its easier to fix issues people get

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

      Same thing happened to me!

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

    i try do it in android it seem not working properly. like when u collect the item. the item not dispeared and not add to inventory. can anybody help me

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

    whew. all this stuff is way over my head but it works. thanks for the tutorials.
    might have to watch em a few more times

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

    Tip: when using the icons download his meta file to to separate each icon like his icons or edit ur meta file using notepad and copy paste his meta file

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

    instead of doing x_start and y_start you can use Vector 2

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

    This is a great tutorial and I thank you for putting it together! One small change I would suggest is it's a little odd for the actual buffs that get applied to the items to have a min and max, and for the buff definitions on the ItemObject to have a value. I would make these two different types. The BuffDefinition can include more properties, like "weight" (likelihood of that buff being applied), and then some method would apply Buffs to an Item based on the BuffDefinitions defined on the ItemObject. With this approach, you could actually define lots of BuffDefinitions for an ItemObject and have it randomly apply one or more when an Item is created so that all Items of the same type don't always have the same buffs.

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

    You sir are the best content creator I have found for Unity tutorials hands down . You make it so easy to follow through and give us such insanely cool concepts to apply to our games. Thank you so much and hope to see you push out more content soon!

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

    i deleted all of my items because i was having a problem where some were the same ID and now when i make new ones it says The Given Key was not present in the dictionary... can someone help??

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

      @Karlson Keel This just saved me untold amounts of time and stress. Thank you for taking the time to respond to the original comment!

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

    I think this should be remade independent of the dependencies, meaning. It's a solo project of just a loot/item buffs & stats that isn't linked to the entire project.
    Allows for people to incorporate into their game rather than the tutorial game.

    • @eatower2
      @eatower2 13 дней назад

      Is that not actually what this is?

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

    Third video and an unfixable nullreferenceexception. I give up. Just downloading the damn scripts now. And watching the videos to set whatever the hell needs to be set

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

    How to get rid of any errors:
    1. Go to Unity and let it compile your code.
    2. Comment out any lines that have errors in them.
    3. Profit.
    4. So apparently we don't have any errors!

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

    Hi! I really love the way you code and teach, great job!
    I have weird problem, when I pickup an item, his sprite is not the same I’ve set up in the scriptableobject. I have no idea what is causing this issue, and in the console there’s no error.

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

      Strange, can join my discord and shoot me some screen shots and it will be easier to help!

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

      @@CodingWithUnity I have same issue. When i started digging around i realised that mu item Objects doesnt update their ID'S even if u create new Items their ID stay at 0. If i change them manually everything works. Havent found where in code it actualy breaks.

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

      @@DrunkCepums211 hey did you manage to figure this out?

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

      I have the same problem did you figure it out?

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

    Not sure if anyone else had this problem but if you're finding all of the items in your inventory get an ID of zero, try bouncing Unity and Visual Studio. I spent about an hour trying to figure out why my items all came up the same in my inventory. Could be a couple of things, renaming the Item class, or quirks of the whole SerializationCallBack thing, but whatever the case, restarting Unity and VS fixed it =)

  • @stankbugmusic
    @stankbugmusic 11 месяцев назад

    my items without buffs won't stack! im so close to having this video done. the only thing that off is my items without buffs don't stack! help!

    • @stankbugmusic
      @stankbugmusic 11 месяцев назад

      figured it out! these videos are great! and very helpful. anytime ive gotten stuck (this being the worse one yet) I just rewind and pay even closer attention. its all there, just gotta go thru it a few times lol

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

    I keep getting an error about a null reference exception when i try to pick up the item. It gives me hundreds of errors because its spawning lots of prefabs? Im confused and need help thx

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

      Did you ever get this fixed? i feel like i helped you on discord but im not sure

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

      ​@@CodingWithUnity I also ran into this problem. While debugging I found that it would skip over the rest of my function once it got to:
      obj.transform.GetChild(0).GetComponentInChildren().sprite = inventory.database.GetItemByID[currentSlot.item.ID].itemSprite;
      because of the null reference exception, so it wouldn't get to the step where it's added to the itemsDisplayed dictionary, which would cause the for loop to instantiate the item display prefab indefinitely as it would never satisfy the conditional to stop instantiating them. I absolutely don't understand why it can't find the sprite, because it is in the intellisense so I know it knows it's in there, and I set the sprite in the inspector.
      But it DOES work when I don't use GetChild(0). So if I use
      obj.GetComponentInChildren().sprite = inventory.database.GetItemByID[currentSlot.item.ID].itemSprite;
      it works. You said we would see why you did it that way, but I watched the whole thing and I don't think you explicitly mentioned why.

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

      I figured out my problem. It's that I didn't have an image in the spot referenced by GetChild(0). I thought I could count on it to reference the first object in the hierarchy of my prefab but I guess that counts as the parent, or something. So I dropped in an Image and made sure it was the first thing in the list so GetChild(0) would pick up on it.

    • @oit2.012
      @oit2.012 4 года назад

      @@SilentscufflE how did you put in an item and make it so that GetChild(0) would pick it up?

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

      @@SilentscufflE yeah, how did you do that

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

    PLEASE HELP
    My code
    Public void OnAfterDeserialize()
    {
    for (int i = 0; i < Container.Items.Count; i++){
    Container.Items[i].item = database.GetId[Container.Items[i].ID];

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

      I'm a little late but you just have to line out the code because it becomes irrelevant ( And im using the JSON save version)

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

      @@freshedpotato Ya I figured that out a while ago but thanks for helping me out just in case I didn't fix it!

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

    I'm having a lot of trouble understanding. In the coding part, I had a hard time after the second video. What do you think I should work on to make up for my shortcomings?

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

    'inventoryObject.databse' is inaccessible due to its protection level
    im getting error at 13:11

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

      Hi super late, but for anyone else watching this tutorial. I had the same issue at one point. It was because database was still set to private instead of public in the InventoryObject script.

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

    I had my Item class keep a reference of the Item Object it used to populate its variables, and I built my items to extend from important distinguishers, so I could easily add buffs based on them. +10% to Melee weapons/ +8% to Sword damage/ etc
    SO = Scriptable Object
    AB = Abstract
    So...
    SOAB_Item => SOAB_Equipable => SOAB_Melee => SO_Sword
    So, I can simply check if the item is a subclass of SOAB_Equipable, to determine if it should/not stack.
    if (_item.itemSO.GetType().IsSubclassOf(typeof(SOAB_Equipable))){
    // Don't stack
    } else {
    // Stack
    }

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

    Followed the tutorial line for line and have come across an error:
    InvalidCastException: Specified cast is not valid.
    InventoryObject.LoadInventory () (at Assets/_Scripts/Inventory/InventoryObject.cs:63)
    - InventoryObject.cs line 63:
    container = (Inventory)formatter.Deserialize(stream);
    Yes my container variable is all lowercase.

  • @512Squared
    @512Squared 2 года назад

    IFormatter, Binary Formatter and Formatter are now obsolete and prohibited in .Net Core 5.0.
    So, that leaves Json or XML. If you don't want it to be readable, consider applying XOR-encryption to the save strings (just Google)

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

    If anyone here is having null reference exceptions, check to make sure that the "image" component is the first child of the inventory slot prefab. I was stumped for half an hour because of this.

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

      @TFed It is the first child and I'm still getting that error. Dude how'd you fix it. I've been struggling with this for about 2 days now

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

      @@zerocount_ It's likely that your null reference exception has a different cause than mine did. If you haven't already done so, I would recommend checking over each scriptable object in the inspector to make sure the exposed references have been assigned (make sure the player inventory references the database, make sure the sprites are assigned to the items, ect.).
      In case you didn't know, a null reference exception is an error that is thrown when you try to access an object that isn't assigned to anything. To narrow down the issue, go to the line where the error occurs (the unity debug console should tell you which script the error occurs and also which line), and try printing (using the print() command,) the name of the object you are trying to reference. (all gameobjects in unity have a "name") If that also throws the same error, that means that the gameobject isn't being assigned at all. Otherwise, check to make sure that the name of the gameobject matches what you want it to be. In general, the print() command is a useful debug tool in my experience.
      (Edit)
      In the inventoryObject script, do you have "database" set to public or private? I have it on public, and it is manually assigned to the database object in the inspector. He forgot to tell us that in the video

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

      If what your talking about IS what I think it is then I had the same problem too. It took me so long to figure out what the problem was and i literally facepalmed when i fixed it. In the DisplayInventory script, make sure you have:
      using System.Collections;
      using System.Collections.Generic;
      using UnityEngine;
      using TMPro;
      using UnityEngine.UI;
      using UnityEngine.EventSystems;
      using UnityEngine.Events;
      public class DisplayInventory : MonoBehaviour
      {
      public GameObject inventoryPrefab;
      public InventoryObject inventory;
      public int X_START;
      public int Y_START;
      public int X_SPACE_BETWEEN_ITEM;
      public int NUMBER_OF_COLUM;
      public int Y_SPACE_BETWEEN_ITEMS;
      Dictionary itemsDisplayed = new Dictionary();
      void Start()
      {
      CreateDisplay();
      }
      void Update()
      {
      UpdateDisplay();
      }
      public void UpdateDisplay()
      {
      for (int i = 0; i < inventory.Container.Items.Count; i++)
      {
      InventorySlot slot = inventory.Container.Items[i];
      if (itemsDisplayed.ContainsKey(slot))
      {
      itemsDisplayed[slot].GetComponentInChildren().text = slot.amount.ToString("n0");
      }
      else
      {
      var obj = Instantiate(inventoryPrefab, Vector3.zero, Quaternion.identity, transform);
      obj.transform.GetChild(0).GetComponentInChildren().sprite = inventory.database.GetItem[slot.item.Id].uiDisplay;
      obj.GetComponent().localPosition = GetPosition(i);
      obj.GetComponentInChildren().text = slot.amount.ToString("n0");
      itemsDisplayed.Add(slot, obj);
      }
      }
      }
      public void CreateDisplay()
      {
      for (int i = 0; i < inventory.Container.Items.Count; i++)
      {
      InventorySlot slot = inventory.Container.Items[i];
      var obj = Instantiate(inventoryPrefab, Vector3.zero, Quaternion.identity, transform);
      obj.transform.GetChild(0).GetComponentInChildren().sprite = inventory.database.GetItem[slot.item.Id].uiDisplay;
      obj.GetComponent().localPosition = GetPosition(i);
      obj.GetComponentInChildren().text = slot.amount.ToString("n0");
      itemsDisplayed.Add(slot, obj);
      }
      }
      public Vector3 GetPosition(int i)
      {
      return new Vector3(X_START + (X_SPACE_BETWEEN_ITEM * (i % NUMBER_OF_COLUM)), Y_START + (-Y_SPACE_BETWEEN_ITEMS * (i / NUMBER_OF_COLUM)), 0f);
      }
      }
      I was missing one and it messed the whole thing, I could be wrong but it fixed mine.

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

      @@isaaccunningham59 This acually fixed it thanks!!!

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

    It took me 9 hours to go through 2 videos XD.
    I still don't exactly understand what I did or rather how I did it. I'm going to break it up into pieces and go back over it.
    It's the interactions that's confusing me. Speaking of, I am thinking of going with an Interface for item pick up. I want my NPCs to have their own inventory. I really will have to spend 2 hours tomorrow just rewatching 1&2 side by side with the code. The small victory is nothing broke. I got a KeyNotFoundException but simply running it again helped.
    For folks who got stuck close to the end after setting up the Save/Load key commands. Be sure to click the game window before pressing space or keypad Enter. When you move the transform in the scene view it makes controls of the game inactive. So the keydowns wont count. That threw my KeyNotFoundException for the library, since I was loading from something that had nothing in it.

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

    you will comment selected lines with CTRL+K,C,and uncomment with CTRL+K,U
    you´re welcome

  • @Time-Eraser
    @Time-Eraser 3 года назад +1

    I got half way through this video and unity crashed. Haven't saved since I started this series. I guess it's an opportunity to try again hahaha

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

      Gotta love unity :)

    • @Time-Eraser
      @Time-Eraser 3 года назад +1

      @@CodingWithUnity Haha yeah, thanks for your vids btw. Seems great so far.
      Got stuck on GetComponentsInChildren vs GetComponentInChildren for about an hour after I got back to this spot XD

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

    why when i pick up an item the inventory starts to spam infinitely objects? :(

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

      Did you fixed this problem?

  • @Paul-rd5zk
    @Paul-rd5zk 4 года назад +1

    Can't find my sprites when i have it saved in assets I'm using unity 2020. Anyone know why they dot show up in sprites? Thanks

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

      Im not too sure, haven't switched to 2020 yet

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

      If you created your own as I did, go to the images/sprites and change the "Texture Type" to Sprite(2d and UI). That was the problem for me

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

    So uh yeah just spent the last 4 hours wasting my time because I decided I want to add rocks that you can mine that give you a stone Item, but instead of it giving you an "ItemObject" item, it gives you an "Item". which pretty much screwed up my whole inventory system. but glad I found out the problem, this tutorial was 10/10 so far.

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

    I don't know why but database was not setting the id of the items, i did have to create an OnEnable() and put there the items[i].id = i;
    maybe i got lost making all the changes at the begining =(
    Thanks for your videos!

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

    I had a problem with this , I am halfway through the video so I dont know if you address but if you use this method than switch scenes than go back. All the info of the inventory is saved except for the icon image.
    Edit: to fix this you simply set the sprite of objChild to the imiage of the object in the CreateDisplay like you do in the Update.

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

    Hey!
    How would you go about limiting the amount of items the player can hold?
    I've been following so far and it's exactly what i needed but I have no idea how I would implement a limit of 4 item slots for the player inventory.
    Please help, thank you

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

      In more detail, I would like to have 4 slots and place a limit on how many items can fit in one slot and hopefully allow them to increase their slot maximums through gameplay upgrades. So, 4 slots of 5 items each could become 10 items each and so on.

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

      You can join my discord and i can try to help you a bit, but your going to mostly have to figure it out on your own unfortunately

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

      @@brianbenedetti5911 Haven't tried it, but should be pretty trivial to implement via the `InventoryObject.AddItem()` function. In the beginning of that function, add something like `if (Container.Items.Count == 4) return`. This will get you halfway there. To maintain stacks, you could turn that if statement into an` else if` after the item stack if.
      What's happening there, is it will first check for the presence of that item in your existing inventory slots, if the item is not in any slot and you have less than 4 items, it will add it. Otherwise the function will just return. There's a lot of ways to accomplish this, but that's just a quick fix.

    • @5moreminutesipromise55
      @5moreminutesipromise55 3 года назад

      Thought I would show what I did to limit the number of slots.
      First added the following top if statement to InventoryObjects.cs
      public void AddItem(Item _item, int _amount)
      {
      if (Container.Items.Count >= 20)
      {
      return;
      }

      if (_item.buffs.Length > 0)
      {
      Container.Items.Add(new InventorySlot(_item.Id, _item, _amount));
      return;
      }
      for (int i = 0; i < Container.Items.Count; i++)
      {
      if (Container.Items[i].item.Id == _item.Id)
      {
      Container.Items[i].AddAmount(_amount);
      return;
      }
      }
      Container.Items.Add(new InventorySlot(_item.Id, _item, _amount));
      }
      This still allowed items to be destroyed so I added the top if to the Player.cs to stop that.
      public void OnTriggerEnter2D(Collider2D other)
      {
      if (inventory.Container.Items.Count >= 20)
      {
      return;
      }
      var item = other.GetComponent();
      if (item)
      {
      inventory.AddItem(new Item(item.item), 1);
      Destroy(other.gameObject);
      }
      }

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

    probably the best tutorial series on inventory system on RUclips, I am currently following this and was wondering if there is a dropping system in the later part?

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

    thanks you, you saved my game, for the layout of inventory, you could use gird layout group, it could automatically adjust.

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

    Aren't there much worse issues with binaryformatter than just the end-user being able to edit the saved file?

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

    Sorry but where is the sprite package to import? Thank you very much for the tutorial

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

    Thank you so much for making those videos. I'm grateful there are pro's who willing to share their knowledge ~^_^~

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

    I know I'm a bit late to the party here, but this is great! Thanks :)

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

    Can someone help me. Everytime I add new item the player inventory does not auto populate the buff. Its always set to size 0

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

    Awesome Loving this series. Thanks so much, looking forward to the next video. !!!

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

    how to load and save data without clicking space or enter ? i try to put the load function and start function, also the save function on onDisable but the data is not save when i start the game, all the data i have is deleted but when i click the space to save data and click Enter to load data the data has been saving and loading ? how do i fix this? can someone help?
    Thanks!!

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

    when i press load it creates new slots but doesnt replace the previous slots, does anyone else get this problem? by loading multiple times?

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

      Can join my discord and i can help you easier!

    • @eatower2
      @eatower2 13 дней назад

      You figure this oneout?

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

    PLEASE HELP!!
    My Code
    public void OnAfterDeserialize()
    {
    for (int i = 0; i < Container.Items.Count; i++)
    {
    Container.Items[i].item = database.GetIteM[Container.Items[i].ID];

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

      I'm a little late but you just have to line out the code because it becomes irrelevant ( And im using the JSON save version)
      dont like out the void but line out the for loop and that

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

    Absolutely superb!!! I have not used sprites before, could somebody tell me where to look for the sprites sheet indicated in the video. Thank you in advance for your help!

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

    At 13:54, where is the Source Image: UISprite from? Is the name important? is the image important?

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

    this was a lot of work and i REALLY appreciate it. it helped me save a huge amount of time to figure all of this out myself… many thx indeed!!

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

    The two dislikes are people who made syntax errors, and didn't try to fix them.

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

    I was the 420th like on this video. Thank you for the awesome tutorial series.

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

    IF THE INVENTORY UPDATE SCRIPT, WONT WORK WITH THE ICON DISPLAY FOR THE ITEM READ THIS
    If u name the itemobject's icon sprite Display, it causes an error cuz the image default object(things prebuilt into unity) also uses a variable named Display. Change its name and it should worj

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

      i had the same problem but that didn't fix it

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

    I learned so much from this. THANK YOU

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

    Hello, I just started getting this error mid way through the video "Assets\Code and Scripts\Inventory Scrips\DisplayInventory.cs(15,16): error CS0246: The type or namespace name 'InventorySlot' could not be found (are you missing a using directive or an assembly reference?)" is there a way to fix this?

    • @512Squared
      @512Squared 2 года назад +1

      A NameSpace just means the script is being referenced via its folder path and its scope is being set to this folder (Google scoping if you don't know what that is).
      You can just remove the namespace attribute to remove the error, but then all your public or static methods will be globally available, which you may or may not want.
      When you create a C# file from inside your IDE, you'll notice it adds the Namespace automatically.

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

    Excellent series of tutorials. Well done and thanks.

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

    #Coding With Unity will i be able to add health from an Item?

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

    11:46 how did you made transparent icons?

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

    Everything is working fine in the Unity Editor and I've tested it a lot, but as soon as I build and run the project I get a NullReferenceException: Object reference not set to an instance of an object
    at DisplayInventory.UpdateDisplay (). Loops over and over and FPD drops obviously. Any idea why the build wouldn't be working but the editor works? Let me know, its greatly appreciated.

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

      I've read some comments here and a couple noted its covered in part 5. I will look into it!

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

    17:39

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

    Loving this tutorial. I have a quick question. In the InventoryDisplay.cs Script the "GetComponentInChildren" keeps getting flagged with "'MediaTypeNames.Image': static types cannot be used as type arguments". Any idea why?

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

      Not 100% sure, but you could make another script called ItemDisplay or something and just put the links to the child images inside that script and do a get component for that script instead of the image or something

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

    Hello, I have a question: How can I remove an InventorySlot form the list through code? I want to remove an item after using it. I've tried using " inventory.Container.Items[i].AddAmount(-1);"
    but the inventory slot keeps storing the item sprite and information with the amount of 0. Can you help me? Thanks in advance!

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

    17:46 Making attributes *note for self

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

    I’ve got a question, I’ve been using this inventory system on a game I’m working on (amazing tutorials btw, thank you) and someone brought up to me that I shouldn’t be using the binary formatter because it has security vulnerabilities 😅 are there other options for unity games? Are they easy to swap out?

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

      If your making a single player game it does not matter. Do not waste time on things like that. The customer paid money for your product so let them hack it if they want. Even if it's free, you should be happy someone cares enough about your game to hack it. If it's multi-player then it should be in a dB on a server.

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

    Okay to anyone who tries to pickup an item and gets the weird console message stating the getcomponent of image part needs a reference to a sprite or image or whatever, you need to change from (UnityEngine.UIElements) to (UnityEngine.UI) this took me a solid 30 minutes to trouble shoot.

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

      This happens often, gotta watch those imports with the new ui stuff unity added

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

    I'm having a bit of a problem. The Item objects all have a child object called "New Sprite" and I must have missed a step because I cannot figure where that came from. I can get the inventory to work by manually adding a sprite to each Item parent but then the name will be the same as the sprite that I add. So, I must have missed something and I'm pouring over the first three vids to find what I missed but so far I haven't found anything. Anyone? Thanks in advance.

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

      Did you figure this one out? I also seemed to have blipped out and missed the connection...

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

    You are the best Unity teacher on this platform.

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

    Looking forward to the continuation of this Series, of all the inventory systems I have been doing lately this is the best one coding wise and explanations.

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

      Shouldn't be too much longer before i manage to get it out!
      I decided to do item swapping for the next video, which i wasnt originally going to do but figured i needed to do that before moving onto the equipment screen cause its sort of a start to doing the actual equipping part

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

      Got sick so its taking longer to get the video out, sorry. Thought i was getting better then got worse :D

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

      @@CodingWithUnity vitamin c and quarantine lol

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

    Nice video. Is there a way to make one item delete from a stack?

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

    Dude, I'm learning so much from those videos, no cap!
    Love it

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

    are you chris ulmer from S.B.S.K.?

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

    I have been watching the series and trying to find out if you fix this issue. On the database, the Item IDs are based off the for loop and the order of the elements in the Items array. If the order of the items in the Items arrays changes, then the items get different IDs. Do you change this at some point so items will maintain their IDs and are not dependent on the order of the elements in the array? Great tutorial though, I have learned a lot. Thank you!

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

      Don't think so, can if you want to tho. Just add a key variable to the scriptable object

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

    Any idea why sometimes I pick an object up and it gives me more than 1 even though there is only one object there?

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

    I absolutely love this video series. I know its old but it is still an invaluable resource for anyone looking to make video games.

    • @DesignMade-Easy
      @DesignMade-Easy Год назад

      somehow the itemprefab is being duplicated infinitly getting error on uodateDisplay 🙁

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

    13:01 there is no reference to .uiDisplay
    where did you pull that from...

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

    Is it possible to have different images (on ground and on inventory) for the same type of item to represent different buffs?

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

      Sure, but does it make sense to have to make multiple copies of every image because you want to display buffs on them? Id suggests coming up with a way of dynamically displaying that or you will find you're creating to much work to be done.
      Albeit if its a tiny game with only a couple items, then ignore me :)
      Also, I would not be able to help you program it. But sure it's possible. (would be to hard to try and show you how in comments)

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

    does this mean that i cant have multiple of the same item object and still have diffrent values of those item objects???

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

      its not really set up for diablo style item stats, but you can modify it to do that, sure.

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

    9:38 cheeky parenthesis change

  • @Alex-hv5cs
    @Alex-hv5cs 4 года назад

    Great tutorial series. Everything is very clearly explained.