Drag and drop in Unity UI - create your own inventory UI!

แชร์
ฝัง
  • เผยแพร่เมื่อ 4 ต.ค. 2024

ความคิดเห็น • 179

  • @Luluskuy
    @Luluskuy ปีที่แล้ว +5

    Just from the first few second I watch your video, I already know your tutorial was extraordinary. Then I got to 04:50 mark. I was wrong, it was more than that! This is the type of tutorial that everyone hoped to see when they need one.

    • @CocoCode
      @CocoCode  ปีที่แล้ว +4

      Thank you! I spend a few hours on those animations ;)

  • @bertiedev6478
    @bertiedev6478 ปีที่แล้ว +36

    For anyone that wants the items to swap slots when dropping on a full slot here is how.
    public void OnDrop(PointerEventData eventData)
    {
    if(transform.childCount == 0)
    {
    GameObject dropped = eventData.pointerDrag;
    DraggableItem draggableItem = dropped.GetComponent();
    draggableItem.parentAfterDrag = transform;
    }
    else
    {
    GameObject dropped = eventData.pointerDrag;
    DraggableItem draggableItem = dropped.GetComponent();
    GameObject current = transform.GetChild(0).gameObject;
    DraggableItem currentDraggable = current.GetComponent();
    currentDraggable.transform.SetParent(draggableItem.parentAfterDrag);
    draggableItem.parentAfterDrag = transform;
    }
    }

    • @Hashishin13
      @Hashishin13 ปีที่แล้ว +1

      Very helpful I hope it gets pinned.

    • @Fr33zE_YT
      @Fr33zE_YT 3 หลายเดือนก่อน +1

      Thank you so much!!!

    • @n0v3g4plays3
      @n0v3g4plays3 3 หลายเดือนก่อน +1

      Very nice! I cleaned it up a bit, this does the exact same:
      public void OnDrop(PointerEventData eventData)
      {
      GameObject dropped = eventData.pointerDrag;
      DraggableItem draggableItem = dropped.GetComponent();
      if(transform.childCount != 0)
      {
      GameObject current = transform.GetChild(0).gameObject;
      DraggableItem currentDraggable = current.GetComponent();
      currentDraggable.transform.SetParent(draggableItem.parentAfterDrag);
      }
      draggableItem.parentAfterDrag = transform;
      }

  • @robertmcgraw2393
    @robertmcgraw2393 ปีที่แล้ว +25

    THANK YOU SO MUCH!! I am self-taught and I've been working with Unity and C# part time for the past couple of years! The inventory system is something that I have not found a decent tutorial on that didn't feel like a big pile of spaghetti!! You are SO clear and precise with your explanation of the "drag and drop" portion (which had always given me the most headaches)! I am definitely going now to watch your full inventory tutorial! I appreciate you SO SO much for helping me get over this massive hurdle!!!

  • @Santanu_Pal
    @Santanu_Pal ปีที่แล้ว +10

    Your teaching process is so clear and simple and very logical fold by fold.
    Appreciate your hard work. Looking for more videos for you.

  • @piotrszymanski8325
    @piotrszymanski8325 ปีที่แล้ว +5

    M8, you are one of the best! Everything showed, everything explained, nice clean and neat, without speeding and uselest trash talking, keep on going! Fingers crossed for your success!

    • @CocoCode
      @CocoCode  ปีที่แล้ว +1

      Thank you very much! Dzięki! 🎉

  • @brandonmitchell-kiss2533
    @brandonmitchell-kiss2533 8 หลายเดือนก่อน +2

    This is one of the best tutorials I've ever seen for unity! Great teaching skills here!

  • @meenuchan7946
    @meenuchan7946 ปีที่แล้ว +2

    Thank you so much for this awesome tutorial. In my game, I had text as a child for my draggable item. I wondered whether raycast target will work or not. But it worked well.

  • @tahahamifar
    @tahahamifar 2 หลายเดือนก่อน

    this video is absoulte Magic! better than any other tutorial about Drag & Drop system in youtube.

  • @DwarvenStudios
    @DwarvenStudios ปีที่แล้ว +2

    Thank you so much, I was watching the full inventory tutorial but the dragging didnt seem to work, watched this tutorial and now everything works PERFECTLY.
    On a side note, if anyone wants have more GO's like buttons under their items, dont add the grid layout group and just add an
    transform.position = parentAfterDrag.position at the BEGGINING of the onEndDrag method. If you add it in the end it will just offset your item which you do not want.

    • @Aggroknight62
      @Aggroknight62 2 หลายเดือนก่อน

      DUDE YOU'RE AMAZING. That somehow has my object snapping back to it's original place, where the whole Grid Layout wasn't doing anything. You're a legend!

    • @DwarvenStudios
      @DwarvenStudios 2 หลายเดือนก่อน

      @@Aggroknight62 Glad I helped you! Funnily enough, I will have to re implement this later in Godot and then in UE5 (our current new main engine). I dont even know what I wrote now as after a big break of working, though I do recall this issue in some slight manner.

  • @lagrangepoint9386
    @lagrangepoint9386 ปีที่แล้ว +2

    My guy, you have criminally few subscribers for such amazing content.

  • @StealthyShiroeanGames
    @StealthyShiroeanGames 8 หลายเดือนก่อน

    Thanks for this tutorial! I had no idea that Unity had these interfaces built-in. It's pretty cool how relatively easy it is to make a drag & drop system like this!

  • @tower1990
    @tower1990 6 หลายเดือนก่อน

    The cleanest explanation on TH-cam. Thank you so much sensei!
    My stupid brain still don’t understand fully why the ray cast matters. As OnDrop should be triggered when a draggable item is released and dropped onto it. It should detect whatever object that’s colliding with it, and not the position under our mouse pointer. Strange.
    Hopefully someone from the community could kindly explain the logic behind. Thank you!

  • @jagdpanda
    @jagdpanda ปีที่แล้ว +2

    if you're struggling to get this to work on a screen space - camera canvas, try getting the hit.point of a raycast screenpointtoray in the ondrag event to put the item at

  • @wyrda2452
    @wyrda2452 ปีที่แล้ว +2

    This was a beautiful Unity UI tutorial series. Hoping to see more!

  • @steved.1091
    @steved.1091 2 ปีที่แล้ว +2

    You earned yourself a new subscriber. I've been following your content for some time, and it seems to me that you're quite knowledgeable in Unity's UI side of things. Keep up the good work 👍👍👍

  • @chiekokurokumo
    @chiekokurokumo 9 หลายเดือนก่อน

    Agreed with statements above. Everything was so well laid out and explained so well. I appreciate this a ton!

  • @arnebiermann4858
    @arnebiermann4858 ปีที่แล้ว +1

    Holy Shit.. Your explanations, especially the ones with custom animations are so damn good!
    Thanks bro :D I understood all of that very well :)

  • @argentumstaar
    @argentumstaar ปีที่แล้ว +2

    I love you so much already! You helped me with something that no other tutorial I've found could, and in such a clear and elegant way too! ^^
    I subscribed.

  • @ДимаРусика
    @ДимаРусика ปีที่แล้ว +1

    Best drag and drop tutorial

  • @vitriolicAmaranth
    @vitriolicAmaranth 11 หลายเดือนก่อน +3

    Can't you just change layer order to solve the "sliding under slot" problem (by adding a canvas component to the object to gain control over the layer sorting)?
    Which is not to diminish the value of this video with a nitpick. Much more clear and educational than most tutorials. I've been devouring courses about making inventories, including paid ones, because it's the first thing I've encountered that has given me trouble and felt especially complex for what seems like a simple feature, and this is one of the best videos I've seen on the subject.

    • @jumpkut
      @jumpkut 11 หลายเดือนก่อน

      you could, but that's not really the problem. the problem is that the slot now contains two items. You don't want that. So either have it be illegal to drop another item, like in the video, or have the items swap places.

    • @CocoCode
      @CocoCode  11 หลายเดือนก่อน +2

      Thank you for the detailed comment! Please keep in mind that sometimes I need to take shortcuts or simplify things to make tutorials more accessible for beginners. That being said, I am strongly against adding a classic Unity layer sorting. I really like the Unity UI approach to sort order based on hierarchy (like in Photoshop). Also this approach (of changing parent on the start of the drag) doesn’t sound bad to me - technically when you start dragging item it’s not part of this slot anymore.

    • @lpa9189
      @lpa9189 11 หลายเดือนก่อน

      Good point. However, you can't move a canvas directly. You'll need to parent the movable object by an object with a canvas. You can then modify the sorting layer of the parent canvas.

    • @vitriolicAmaranth
      @vitriolicAmaranth 11 หลายเดือนก่อน

      @@CocoCode Yeah, when I had time later I tried my solution and it didn't work perfectly in all use cases anyway. Yours seems to work consistently across each UI I've used it in so I don't think I was right to nitpick it in the first place.
      Between the help I got from your video with the drag and drop functionality and picking apart some inventory examples from other people to work out the advantages and disadvantages of different data structures and how to design things for my own game I'm happy to say my inventory system is complete and I'm already a week deep in making a complex alchemy system, which is super easy with an inventory system that already works well.

    • @vitriolicAmaranth
      @vitriolicAmaranth 11 หลายเดือนก่อน

      @@jumpkut I was talking specifically about when the item "slides under" the slots when you pick it up, but I went with the latter solution. That part was very simple to program, though. There is probably an even simpler way but my first attempt worked perfectly so I haven't messed with it afterward. I simply cached each item's index in the inventory array as well as each item's parent slot, then assigned item 1's parent transform (slot) and index to item 2 and vice versa.
      Edit: And a minute ago I incidentally learned about using tuples to do the same thing, reducing 7 lines of code to 2 lines of code.

  • @kotokk
    @kotokk ปีที่แล้ว +9

    I can not seem to understand. When I try to drag an item it disappears and then teleports back to its position when I release. I made sure that our codes are the same and everything else basically. But it just doesn't work...

    • @jpikachups
      @jpikachups 8 หลายเดือนก่อน +1

      Probably thats because of the "transform.SetParent(transform.root)" when you begin dragging, your item goes directly to the root of your hierarchy that is not even on canvas. Your item just need another parent inside of the canvas hierarchy.
      Instead of this, lets say you can create a new variable with "public Transform goose" and assign with any object on this canvas, then you change the line with "transform.SetParent(goose)". Now it should be working, goose is a very kind parent

    • @JohnWLivingston
      @JohnWLivingston 2 หลายเดือนก่อน

      Had this issue. I deleted my item object and created an new one and it worked. Maybe try that?

  • @2kool4programmingschool
    @2kool4programmingschool ปีที่แล้ว

    Thanks for teaching me this! Just like Sam Hogan’s Cellular Automata-inspired game, i’m making a Level Maker in Unity.

  • @Crowbar
    @Crowbar 5 หลายเดือนก่อน

    Exceptional tutorial! Really nice graphic design elements!

  • @Jimaniki
    @Jimaniki 2 ปีที่แล้ว +1

    Yeahhhh you're back !
    Thank you !

  • @emreucmaz3956
    @emreucmaz3956 หลายเดือนก่อน

    Great explenation. Thank you so much!

  • @Grinwa
    @Grinwa 2 ปีที่แล้ว +5

    Thank you ❤️
    Can you please do a video or just explain how to get info of the object stored in the table when you drag n drop it there
    And store that info to costume class
    Something like inventory so i need to track each item on it thanks

    • @CocoCode
      @CocoCode  2 ปีที่แล้ว +3

      I’m working on the inventory video - it will be out by the end of the month 🎉

  • @frog2091
    @frog2091 ปีที่แล้ว +28

    If your item is being transferred to some crazy (30000000, 300000) coordinate once you implement the "transform. Position = Input.mousePosition" you might need to get to change it to "cameraNameExample.ScreenToWorldPoint(Input.mousePostition)" but as a new Vector 3 so you can ignore the Z axis.

    • @ThemthingShorts
      @ThemthingShorts ปีที่แล้ว +1

      thank you soooo much bro u saved me

    • @IndianTech_Games
      @IndianTech_Games ปีที่แล้ว

      But it's still not wortking

    • @jamieschooling7631
      @jamieschooling7631 ปีที่แล้ว +1

      It's probably easier to just use transform.position = eventData.position;

    • @boombox8408
      @boombox8408 ปีที่แล้ว

      @@jamieschooling7631 It didn't worked

    • @oldshamen
      @oldshamen ปีที่แล้ว

      You could also just use the position from the eventData that is passed as a parameter to the OnDrag method :)

  • @florykakaa300
    @florykakaa300 2 ปีที่แล้ว +2

    awesome animation!easy to understand

  • @psychoink
    @psychoink ปีที่แล้ว

    Your movies are just outstanding. Amazing job ;)

  • @adirmugrabi
    @adirmugrabi ปีที่แล้ว

    thank you very much for this amazing vid!
    i did it a bit different, but i still learned alot

    • @adirmugrabi
      @adirmugrabi ปีที่แล้ว

      this is my on drop:
      public void OnDrop(PointerEventData eventData) {
      var other = eventData.pointerDrag.GetComponent();
      other.transform.SetParent(transform.parent);
      transform.SetParent(other.lastParent);
      other.lastParent = null;
      }
      it swaps items when you drop one into another.

  • @EarthCrossers
    @EarthCrossers 3 หลายเดือนก่อน

    Great video super easy to follow.

  • @khaelus_dev
    @khaelus_dev ปีที่แล้ว +5

    I have done the swap items logic. In case anyone is interested.
    public void OnDrop(PointerEventData eventData)
    {
    if(transform.childCount == 0)
    {
    Debug.Log("DROPPED");
    GameObject dropped = eventData.pointerDrag;
    DraggableItem draggableItem = dropped.GetComponent();
    draggableItem.parentAfterDrag = transform;
    }
    else //swap items
    {
    Debug.Log("Swap items)");
    GameObject dropped = eventData.pointerDrag;
    DraggableItem draggableItem = dropped.GetComponent();
    Transform originalParent = draggableItem.parentAfterDrag;
    // Swap
    Transform itemInSlot = transform.GetChild(0);
    draggableItem.parentAfterDrag = transform;
    itemInSlot.SetParent(originalParent);
    dropped.transform.SetParent(transform);
    itemInSlot.SetAsLastSibling();
    }
    }

  • @DeveloperJake
    @DeveloperJake 2 ปีที่แล้ว +2

    Ohh this is cool

  • @kureselgelistirici3121
    @kureselgelistirici3121 6 นาทีที่ผ่านมา

    You are wonderful 👏

  • @kyleme9697
    @kyleme9697 2 ปีที่แล้ว

    Wow that was great. Who knew it was so complicated :)

  • @muhammedhatay2451
    @muhammedhatay2451 ปีที่แล้ว +1

    You're goddamn hero! Thanks!

  • @jjs5072
    @jjs5072 7 หลายเดือนก่อน

    Excellent tutorial! Instant Subscribe!

  • @eternalstud3nt
    @eternalstud3nt ปีที่แล้ว

    Just found your channel. Damn those tuts are clean

  • @ghostisbusy2170
    @ghostisbusy2170 ปีที่แล้ว +3

    the eventsystems engine literaly just dosent work, is there any work around? What do i do???

  • @MrZtapp
    @MrZtapp ปีที่แล้ว

    As always, great tutorial

  • @HeyImGlen
    @HeyImGlen ปีที่แล้ว

    This is one fantastic tutorial

  • @FireRingStudio
    @FireRingStudio 11 หลายเดือนก่อน

    You are a genius, thank you so much!

  • @lolol-kt6vp
    @lolol-kt6vp 2 ปีที่แล้ว

    Amazing tutorial! Happy to subscribe you

  • @svenbtb
    @svenbtb 4 หลายเดือนก่อน

    This is a nice quick tutorial, but it's not really great for the Item and the Slot to be so tightly coupled (meaning that the scripts "know" too much about each other). It's better to just make a simple "SetNewParent" method on the DraggableItem, and then simply calling that method from the Slot instead of directly setting it like in this vid. I also recommend doing some kind of error checking, like ensuring that that the dragged item actually HAS the DragItem component, otherwise your game could crash (or throw errors). This is easy to fix with a simple
    if(droppedObject != null && droppedObject.GetComponent()) {//code to set new parent here}
    you also don't have to set image as public, just give it [SerializeField], this will let you edit it in the unity Editor without having to (needlessly) make it Public (which lets other objects mess with that data)

  • @christopheradams2405
    @christopheradams2405 3 หลายเดือนก่อน

    THANK YOU!

  • @TricoliciSerghei
    @TricoliciSerghei ปีที่แล้ว

    Thank you, very you have great tutorials! ;)

  • @mmokzlrsn
    @mmokzlrsn ปีที่แล้ว

    great instruction and demonstration i subscribed and liked

  • @duongphuonggiao
    @duongphuonggiao 4 หลายเดือนก่อน

    I love you so much already!

  • @B34Rocky
    @B34Rocky ปีที่แล้ว +2

    I need help, i can drag the item but it disappears in the game view instantly und never comes back :(

    • @Wabbel
      @Wabbel ปีที่แล้ว

      same problem

    • @ObiGobiGames
      @ObiGobiGames 8 หลายเดือนก่อน

      Same here
      @@Wabbel

  • @davekene
    @davekene 2 ปีที่แล้ว +1

    Great video!

    • @CocoCode
      @CocoCode  2 ปีที่แล้ว

      Thanks David!

  • @erkankumral8988
    @erkankumral8988 ปีที่แล้ว

    Best explanation.. Thank you.

  • @Tobyyx3
    @Tobyyx3 ปีที่แล้ว +4

    Hello, first of all, thanks for the great tutorial!
    My question is, if i have a draggable Item that has one or more children e.g. a text, the snapping does not seem to work. Do you have a solution for this problem?
    Edit: I found it myself: by disabling the target raycast property of the text element.

  • @anneprocter
    @anneprocter 11 หลายเดือนก่อน

    Very helpful!!! Thank you!

  • @chaostellar
    @chaostellar 2 ปีที่แล้ว +1

    amazing, thanks

  • @ScantSword
    @ScantSword ปีที่แล้ว

    INCREDIBLE!

  • @arisaek7764
    @arisaek7764 ปีที่แล้ว

    Great tutorial!

  • @andresaraya5198
    @andresaraya5198 ปีที่แล้ว +1

    can you make a second video where you show us how to add stacks for your items? It would awesome if you can show us.

    • @CocoCode
      @CocoCode  ปีที่แล้ว +1

      Here you can find a full inventory tutorial (that includes stackable items): th-cam.com/video/oJAE6CbsQQA/w-d-xo.html

    • @andresaraya5198
      @andresaraya5198 ปีที่แล้ว

      @@CocoCode thank you so much :D I really needed this

  • @FernandoMontenegro-bc9gh
    @FernandoMontenegro-bc9gh ปีที่แล้ว +2

    You have a video if you want swaping items ??

  • @rrainix
    @rrainix 3 หลายเดือนก่อน

    you could use internal instead of [HideInInspector] public

  • @TegridyMadeGames
    @TegridyMadeGames ปีที่แล้ว

    amazing, thank you.

  • @yudayou2646
    @yudayou2646 ปีที่แล้ว

    THANK YOU SO MUCH!!

  • @gothicdash
    @gothicdash ปีที่แล้ว +3

    Am I wrong or you are using 'image' without assigning it?
    Why you have no errors??

    • @olpacheco
      @olpacheco ปีที่แล้ว

      You proobably forgot to assign it on the editor

  • @Derkells
    @Derkells 8 หลายเดือนก่อน +2

    When I drag and drop my x / y values of the object go from ~25 instantly to over 5,000 in each value making the image disappear, any suggestions?

    • @ObiGobiGames
      @ObiGobiGames 8 หลายเดือนก่อน

      This actually happens to me too. I'm not sure why.
      This is my code:
      using System.Collections;
      using System.Collections.Generic;
      using UnityEngine;
      using UnityEngine.EventSystems;
      public class InventoryItem : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler
      {
      public Transform parentAfterDrag;
      public void OnBeginDrag(PointerEventData eventData)
      {
      Debug.Log("Begin");
      }
      public void OnDrag(PointerEventData eventData)
      {
      transform.position = Input.mousePosition;
      }
      public void OnEndDrag(PointerEventData eventData)
      {
      Debug.Log("EndDrag");
      }
      }
      I've tried debuging the Input.mousePosition and it looks normal but when I actually am dragging the item around the X/Y values are insane (Like 61,222 and similar for the Y)
      Any help on this would be awesome. glad Im not the only one

    • @jjs5072
      @jjs5072 7 หลายเดือนก่อน +1

      @@ObiGobiGames
      @QuailValleyBoyz
      If you are still having issues with this, it seems to be a problem with the coordinate system used by the mouse vs the coordinate system of the canvas: the mouse uses the World Coordinate system, while the UI object uses the canvas coordinate system (local). Read the position value of the mouse and compare it to the position value of the item. If hey are different (even if the mouse is hoovering right over said item) then that's the issue.

    • @chaosroninofmagic1055
      @chaosroninofmagic1055 5 หลายเดือนก่อน

      it happen to me too Really want answer some body help please
      🥺

    • @jjs5072
      @jjs5072 5 หลายเดือนก่อน

      @@chaosroninofmagic1055 If I remember correctly, that issue happened because you are taking (x,y) coordinates from the object in relation to the canvas, and when you drop it, Unity transforms those values to world coordinates. It was something like that.

  • @انار-ف1ع
    @انار-ف1ع ปีที่แล้ว +2

    quick actions and refactoring in vs code is not showing for me, idk why, can anyone help me?

  • @Vinicius-zu3nx
    @Vinicius-zu3nx ปีที่แล้ว

    Thank you!

  • @Klarified01
    @Klarified01 ปีที่แล้ว +2

    Thanks! I have a question though. When I implement snapping, the item glitches to where the mouse is and where the inverntory slot is. It does not snap back when the mouse button is released, instead it teleports constantly between item slot and mouse position during dragging. Can you help with that?

  • @candyyyq
    @candyyyq ปีที่แล้ว +1

    How to make Item appear not only over it's parent slot, but during dragging, over every slot?

  • @LIDOGAMES
    @LIDOGAMES 11 หลายเดือนก่อน

    Really Simple 👍

  • @finesseandstyle
    @finesseandstyle ปีที่แล้ว

    I feel like click once and it drags until you click again is more intuitive like in Minecraft. Pure drag and drop has fewer use cases. Anyway I learned enough to behave like that so thanks

  • @Shonia
    @Shonia ปีที่แล้ว

    Nice animations!

  • @diogofreitas1023
    @diogofreitas1023 ปีที่แล้ว

    Thanks

  • @RichOrignisl
    @RichOrignisl 2 ปีที่แล้ว

    Nice video! :)

  • @ErfanUnityEnglish
    @ErfanUnityEnglish ปีที่แล้ว

    Very nice

  • @linhdev99
    @linhdev99 6 หลายเดือนก่อน

    thanks

  • @DragonEmperor03
    @DragonEmperor03 2 ปีที่แล้ว +2

    Please do make video on how to implement this with new input system and how to do it with keyboard and game pad! Thank you!

    • @enursha13drs
      @enursha13drs ปีที่แล้ว +1

      throw in a start function or Awake, I used awake, Call in - using UnityEngine.InputSystem - then declare your input, findobject of type, boom straight then from there *input declared name* . input

    • @enursha13drs
      @enursha13drs ปีที่แล้ว +1

      new input, make sure it's a pass through and vector 2

  • @Crafted_Tales
    @Crafted_Tales 2 ปีที่แล้ว +2

    can you make level lock and unlock pleaaaaaaaaase

  • @dylansmith5264
    @dylansmith5264 ปีที่แล้ว

    I got it working for the most part, I can move all of them, except for the first one, it just snaps back to its original slot for some reason. Rewatched the vid three times, any clues?

  • @chaosroninofmagic1055
    @chaosroninofmagic1055 3 หลายเดือนก่อน

    i feel like some time i drop its not snap i feel raycast doesnt work well

  • @mattwalton431
    @mattwalton431 28 วันที่ผ่านมา

    i am very new to programing and do not understand why i am not given any suggestions when typing int the public class line any advice?

  • @saishsawant7410
    @saishsawant7410 ปีที่แล้ว

    This is pretty awesome, but what if i want to use merge system , i want to merge two items ?? how to go about that?

  • @tadeasnapackach4496
    @tadeasnapackach4496 ปีที่แล้ว +1

    can u please give me a "ivnentoryItem" script ? I cant find the option there

  • @noniceq2096
    @noniceq2096 5 หลายเดือนก่อน

    Input.mousePos teleport to some weird places like 385101.8 when value is 486

  • @asp_kley
    @asp_kley ปีที่แล้ว

    Please help me here's my error : argumentnullexception: value cannot be null.
    by the way when i'm dragging my object disappears

  • @bharatgupta1937
    @bharatgupta1937 ปีที่แล้ว +1

    The type or namespace name 'DraggableItem' could not be found (are you missing a using directive or an assembly reference?)
    Getting this error. IDK why. I'm new to this line of work
    Can someone help me? I'm using 2021.3.17f1

    • @ReaganSSS
      @ReaganSSS ปีที่แล้ว +2

      Hi Bharat, that specific line of code is referencing a separate "DraggableItem”. Essentially Unity is looking for the script titled “DraggableItem” but is unable to find it. Likely what you have done is named your script something different from what was shown in the video. You can fix this error by writing the name you have given to the script instead of “DraggableItem” since that is likely not a script that exists in your project. For example, I named my first script “Drag” instead of “DraggableItem”, so I needed to change the code to reference the Drag script instead. Hopefully you found this helpful and were able to understand it. If you have further questions feel free to ask and I will try my best to reply.

    • @bharatgupta1937
      @bharatgupta1937 ปีที่แล้ว +1

      @@ReaganSSS that makes sense now. Thank you :D

  • @carloslecina9029
    @carloslecina9029 ปีที่แล้ว +1

    Hello, thx for the tutorial. But It doesn't seem to work at all on Unity 2020 LTS, I don't know why. I follow every step you did. When I drop an item, it always go back to its original slot. My code is 100% equal to yours, no change at all. Can you figure out what's happening, please?

    • @RSinist-12
      @RSinist-12 ปีที่แล้ว

      Did you ever find a solution for this? I'm having the same issue.

    • @RSinist-12
      @RSinist-12 ปีที่แล้ว

      Not sure if you were having the same problem as me, but I hadn't added the InventorySlot component/script to the inventory slot prefab to ensure it was on all inventory slots..

    • @carloslecina9029
      @carloslecina9029 ปีที่แล้ว

      @@RSinist-12 Yes, mostly. I had to rely solely on OnEndDrag and remove any OnDrop method instead. It's quite dirty and I don't like it, but it "works"...

  • @kozavr
    @kozavr ปีที่แล้ว

    Wouldn't be easier to use EventTrigger Component?

  • @soldadopreciso
    @soldadopreciso หลายเดือนก่อน

    How define only a specific slot and avoid to insert in another one.

  • @didikong6333
    @didikong6333 8 หลายเดือนก่อน

    How can I implement Drag and Drop with 2D Objects instead of UI Images?

  • @amyjansevanvuuren2016
    @amyjansevanvuuren2016 ปีที่แล้ว

    If I want this to work between two different parent groups (for example, dragging and dropping between your inventory and a chest), how will I go about this?

  • @SpringDavid
    @SpringDavid ปีที่แล้ว

    Question: Is possible to make a tetris inventory system (ala escape from tarkov) with this?

  • @filemissing5703
    @filemissing5703 11 หลายเดือนก่อน

    how do i apply a filter to a certain slot so it will only accept a certain item?

  • @pantheroathz4734
    @pantheroathz4734 2 หลายเดือนก่อน

    3:18 Idk what I did wrong as I followed every step, but My VS doesn't show me any options to "Implement Interface" when I click on "quick actions and "refactorings" Is there maybe a certain installment missing?

    • @pantheroathz4734
      @pantheroathz4734 2 หลายเดือนก่อน

      also IDragHandler etc is not in colour in my code?

    • @NathanAHH
      @NathanAHH หลายเดือนก่อน

      I had trouble with this too, The way I fixed it is to just type it out by myself, and make sure you have "using UnityEngine.EvenSystems;" At the top of your script

    • @pantheroathz4734
      @pantheroathz4734 หลายเดือนก่อน

      @@NathanAHH I'll try this, thank you

  • @gameplayguide2299
    @gameplayguide2299 ปีที่แล้ว

    My item is going out of the canvas when i am dragging it i did just like in 6:15 but its not working please any solutions for this

  • @AlbertoBerito
    @AlbertoBerito ปีที่แล้ว +2

    I loved the tutorial, but how could I make items swap slots by placing one on top of the other? I have no idea I really need help.

    •  ปีที่แล้ว +3

      if (transform.childCount == 1)
      {
      child = this.gameObject.transform.GetChild(0);
      DraggableItem draggableItem = eventData.pointerDrag.GetComponent();
      child.SetParent(draggableItem.parentAfterDrag);
      draggableItem.parentAfterDrag = transform;
      }
      Look the inventory tutorial

  • @chaosroninofmagic1055
    @chaosroninofmagic1055 3 หลายเดือนก่อน

    do you have any idea to drag object

  • @Enano7
    @Enano7 5 หลายเดือนก่อน

    muy bueno sos un nashe

  • @timed3027
    @timed3027 ปีที่แล้ว

    I can't right click to implement interface, there is no option to implement it.Even I use Crtl+. there are no quick solution. What should i do?

    • @finesseandstyle
      @finesseandstyle ปีที่แล้ว

      Check if you have Miscellenous Files under your Visual Studio project instead of Assembly-CSharp

  • @lma_cristian
    @lma_cristian ปีที่แล้ว

    Hermosa explicación

  • @noofbader6010
    @noofbader6010 ปีที่แล้ว

    يا اسطورة

  • @huninagy3198
    @huninagy3198 ปีที่แล้ว

    Which element is Bacground and Box ?