[Unity Coding Tutorial] Drag & Drop Inventories in Unity!

Поделиться
HTML-код
  • Опубликовано: 14 мар 2023
  • In this Tutorial we go over how to create a Drag & Drop style Inventory from scratch, with features of being able to pick up and drop floor items, and the ability to split and stack items.
    Rogue-Lite Items Tutorial - • [Unity Coding Tutorial...
    UI Images Download -
    drive.google.com/drive/folder...
    Scripts -
    github.com/JosephMask3D/Drag-...
    Follow Me on Twitter / joe3d_
    -
    Local Elevator by Kevin MacLeod is licensed under a Creative Commons Attribution 4.0 license. creativecommons.org/licenses/... incompetech.com/music/royalty-... incompetech.com/

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

  • @farisazhari3583
    @farisazhari3583 4 дня назад +2

    Thanks A LOT sir

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

    For a beginner, this is a bit overwhelming but, nonetheless, a good way to be quickly exposed to deeper C# and Unity concepts (or computer programming in general)

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

    Very informative, thank you man.

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

    Very cool. Some great features like splitting item are execute quiet well and it is also nice that you implemented drop / pickup.

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

    This is awesome! Thanks for the video, Joe. I appreciate the speed you go through the content, as it's a youtube video that can easily pause/rewind as needed.

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

    You are the best. Thank you so much. Pls more of this Videos!!! Intant Subscribed.

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

    Simple amazing, there is no tim wasted in this tutorial. I implemented it with some troubles but only due to my own inexperience😃. It was exatcly what I was looking for.

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

    Not gonna lie, as a beginner i got a little bit overwhelmed with that much info, but holy shit. Subscribed instantly o.O

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

    fr turn the video speed to 0.75 and u'r gone with overwhelming aha, thank your for the tutorial you'r the best !!

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

    This is very impressive!
    Could this be expandable into more inventories? for example a base storage or a chest? I can see in the code that it's coupled to inventory and I wonder how an expansion of the system would work.
    Thank you for a great tutorial!

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

      Yes it could I think. I would try making a chest UI that’s basically identical to the player inventory UI, just in a separate location on the screen, and store item lists in chest object scripts, when the player interacts with a chest the system grabs the list and uses that to populate the chest UI.

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

      That sounds like it could work, I will try that. Thank you for a very quick reply :)
      Do you have a donation site like ko-fi or something similar? I would like to support you in some way to make more great content like this.@@JosephMask3D

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

      ⁠​⁠@@JosephMask3DThat sounds like it could work, I will try that. Thank you for a very quick reply!

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

      @@JosephMask3D Just coming back to this and say that it worked great to make a secondary inventory system for a chest. Although it's a bit coupled and a bit tedious to make more than one, it worked great for just having one more. Thank you again. Is it possible to make a donation to support this and future videos?

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

      @@MrTekui Glad to hear it worked! You might be able to use the Inventory script as double duty for both the Inventory and chest management since they will be so similar, and because you would usually want your inventory open as you use a chest, would just need to add a chest item list variable and update it with the currently selected chest, etc.
      I don't have any donations set up at the moment, but I really appreciate the thought.

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

    Hey, great tutorial. One question tho, why did u delete the license on github? Is this still usable under the old license, or what is the new one?

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

      That was a mistake, apologies. I updated it with an MIT license.

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

      Thanks! @@JosephMask3D

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

    I'm partial to the single item split by default and the 50% split with ctrl held. Mouse wheel dynamic split is sekc, but it don't port to a controller or touch screen easily, and not everyone has a mouse wheel, even in 2023... somehow.

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

      The mouse wheel splitting was just to show something like that is a simple feature to add if wanted, but yeah, it will depend on what platform you are working with if you want or even need something like that.

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

    Is this something that would work for multiplayer, as I'm aware there are a few different things you'll need to do in order for the net code to work with inventories. If it's easy to build off I'll give this inventory a try and go from there.

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

      I guess that depends on what you want to do for multiplayer, synchronization shouldn’t be an issue since the only data that would need to be exchanged would be a string for the item (could be rebuilt into the item class from the clients inventory dictionary) an int for a slot number, and an int for a stacks amount, + the other players inventory size if that changes.

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

    Is it performant to go through all the project files to just find the subclasses of Item? Is there a better way to do this? Maybe add them to the Resources folder or manually add them to an array?

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

      It’s not, but that’s why it’s only done once when the inventory first runs it’s start function and stores the info into a dictionary so it never has to again until a new inventory is created ( which would most likely only be when the game is turned on each time), so it really only affects start up performance. Using the resources folder is a cool idea, haven’t tried it but it would be cool getting that to work. And as far as I know, manually creating an array of classes based on the derived class in Unity is wonky at best. I used a different method in my rogue lite items video of an enumerator and a switch statement, but it’s a bit clunky compared to the dictionary route.

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

      @@JosephMask3D What about the idea of using scriptable objects for the items?

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

      @@ekekw930 I’ve seen that people have had success using scriptable objects for adding abstract classes in the inspector but I haven’t tried it personally. Seems worth giving a shot if that solution works better for you.

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

    Hi, I'm trying to implement a Hotbar system. And I want a way to know if an item is a useable item, I've tried every way that I know I could. But I can't figure it out. If you could help, it would be much appreciate.

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

      Assuming your hotbar is set up in a similar way to the inventory, I would try creating a virtual bool method in the Item abstract class that defaults to false, like this:
      public virtual bool IsUseable()
      {
      return false;
      }
      and any item you want to make useable, just override this method and change the return to true. Then call this method on the item in your hotbar to check if you can use it.
      and for the method that you call to use the item, I would make a virtual void method that returns nothing, and depending on what you want your items to do, would also require a script to affect or a component to grab information from, like this:
      public virtual void Use(GameObject target)
      {
      return;
      }
      and then in the item script which you made useable, you could make something like this:
      public override void Use(GameObject target)
      {
      //Increase targets health
      Player player = target.GetComponent();
      //Check if component was found, if so, heal the player
      if (player != null) player.health += 5;
      }
      the target being a generic game object lets you attempt to grab whatever component or script you would like from the target, which gives flexibility to make any item effect you would like.
      How you pass in the target will depend on how your game is set up, but if you, for example, wanted to make a right click auto cast onto the player, and assuming your hotbar buttons behave similarly to the Item Panel scripts, and your hotbar menu is attached to your player in some way you could search for your player script in the root game object, like this
      public void OnPointerDown(PointerEventData eventData)
      {
      if (eventData.button == PointerEventData.InputButton.Right)
      {
      if (itemSlot.item.IsUseable()) itemSlot.item.Use(transform.root.gameObject);
      }
      }
      Hope this wasn't too much info. For your main question though, just creating a bool method to override to check for useable items should work just fine.

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

      @@JosephMask3D Thanks for the respond. I'll try it out, and let you know how it goes.

  • @grandmax6223
    @grandmax6223 8 месяцев назад

    Are there optimized objects that can be pickup? if there are 2000 of them, there will be lags due to 2 Rigidbody and 2 colliders

    • @JosephMask3D
      @JosephMask3D  8 месяцев назад

      In a situation like that you could put a trigger collider on the player with a simple script to check for hits and call the pickup, then you could simplify the items down to one object.

    • @grandmax6223
      @grandmax6223 8 месяцев назад

      @@JosephMask3D Is every new item a new script? And is it possible to somehow redo it for ScriptableObjects?

    • @JosephMask3D
      @JosephMask3D  8 месяцев назад

      @@grandmax6223 It should be possible, the only info you need to get to the player is the name of the item and an amount. I don’t have much experience with ScriptableObjects though, so how to go about it using them I’m not sure.

    • @grandmax6223
      @grandmax6223 8 месяцев назад

      @@JosephMask3D thx bro

  • @CHASMLLC
    @CHASMLLC 9 месяцев назад

    what would cause the image not to show up ,with no errors and the proper amount of 40 being displayed by 10 in 4 different boxes.. i basically only get the white image from the beginning but in the cavas elements it shows proper name and proper amount added to name.. only thing not working is the Item Icon image.. i get the white square

    • @JosephMask3D
      @JosephMask3D  9 месяцев назад +1

      It might be the directory string in Resources.Load being slightly incorrect, so it finds nothing and sets the image to null, leaving a white square.

    • @CHASMLLC
      @CHASMLLC 9 месяцев назад +1

      @@JosephMask3D thank you very much.. it was my spacing in that very area.. thank u

  • @darkxplayzz
    @darkxplayzz 8 месяцев назад

    Hey! I dont know if you still respond to the comments, but I have a problem. When i drop my items they spawn very far from the player and keep going even futher in the y direction. I've done everything exactly like in the tutorial. Do you know the possible cause of this problem and a possible fix?

    • @JosephMask3D
      @JosephMask3D  8 месяцев назад +1

      So for the spawn location, is your inventory script attached to your player GameObject, meaning the transform that is moving around the level with the player character? The DropItem method uses the transform of the gameobject that the Inventory script is placed on to determine the position to drop the item, the part in the Instantiate call that has *[this.transform.position + new Vector3(0, 1.8f, 0]*, if its attached to another object it will spawn on whatever object the Inventory script is attached to.
      As for the reason its moving forever in the Y direction; Other than giving the Rigidbody some velocity when we spawn our object, the rest of the behavior is handled by the Rigidbody settings in Unity. Maybe check the gravity settings in your Project phsyics settings (the same place that has the triangle of physics interactions, at the top, It should be -9.81)? Or if you mean it falls through the floor maybe check that your root item pickup object (the main parent object for the prefab) can collide with the floor.

    • @darkxplayzz
      @darkxplayzz 8 месяцев назад

      @@JosephMask3D alright, i fixed it

    • @JosephMask3D
      @JosephMask3D  8 месяцев назад +1

      @@darkxplayzz I was working on a reply as I got this 😅. What was the problem if you don't mind me asking?

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

    That's cool, but too quiet

  • @anaanab
    @anaanab 7 месяцев назад

    why dont u speak faster? i think ur not talking fast enough.

    • @Hattori_Fujiyama
      @Hattori_Fujiyama 3 месяца назад +1

      too bad youtube doesn't have a feature built into the player the make the video play faster...