@@johanalmansyah6140 Now, it depends very much on your implementation. But you can do the following thing: In the EquipmentSlot class write a function that clears the slot: pastebin.com/5WZrBEse (the indentation got quite messy in the pastebin) And then all you need to do is to go trough all the slots and call ClearSlot method on each of them and then you could run the initialization method again. This is a hacky and quick way to resolve your issue and a more proper one is in function of your implementation of the inventory and the way you use it. A better approach might be to keep a reference to the initial drop area in the DraggableComponent and have a Reset function which takes the DraggableComponent back to the initial drop area
Hi, thanks for this tutorial ! I got one question: How to make the current dragged object above of all of others objects ? When i use your sample and replace the "f" transparent image with a no transparent image, i got this issue... For example, the apple dragged from the "Gauntels" container to another container like "Greaves", the apple is not always on top if you move it onto from "Gauntels" to "Greaves" and vice-verse Thanks for your answer !
Hello Kunz, I'm happy to hear that you found the video helpful. As for dragging the item back to the inventory, it was a common request from the users and so I did a release with this feature on github, the link is here: github.com/Noixelfer/Drag-DropTutorial/releases/tag/1.0.1
Oh, i forgot to cover that. You creat a DisableDrop condition which derives from DropCondition and in the Check method you always return false. Then you add it to the dropArea when an item is dropped.
@@a.d.6985 @Kiriakos41 @ KratosunBaltasınaSapOlanAdam Sorry for the late reply for this request. I've been planning a second part on this system for a while but it seems that I don't find the time to do it right now, so I've updated the github repository with the bug fixed (you can no longer drop 2 items on the same slot). The link is here github.com/Noixelfer/Drag-DropTutorial/releases/tag/1.0.1 if it has any problems or you have any questions regarding the changes in the code, feel free to ask me and I will answer (you can contact me on discord too). Hope that it helps you all, if you have any other sugestions I would be more than glad to hear them
This is the only one that worked of all the tutorials, thank you. Also, how do i make the item return to the original spot and can move to any other slot?
I m glad it worked for you. As regarding to your question (as i have seen is a pretty popular request) I will do a part 2 video where i will add those features as it a bit much to explain in a comment. I will try to release the video as soon as possible
Hey I know this is a little of a stretch, I am trying to implement the system but what is happening is the following: I drag a weapon to the slot, then try adding another one to the same slot, goes back to inventory so thats working fine. BUt then when i remove the original weapon from the slot and try to drag it again to the equipment slot, it goes back to the inventory. Do you know what could be causing the issue?
Hello. Did you tried to do it with the bow? cause I looked into the project and the bow was bugged (it has some extra components). Also, the bow does not have the weaon component attached so it can't go into the weapon slot. Also, make sure to use the latest release at it had a couple of fixes after the video was release, you can find it here: github.com/Noixelfer/Drag-DropTutorial/releases/tag/1.0.2
Thanks a lot, you made it very easy to understand. I just have one question regarding the EquipmentSlot class and ?? operator. I had no idea about this operator so I googled it and it seems that it's not very reliable while using it with UnityEngine.Object derivatives (GameObjects, Components, MonoBehaviours, ScriptableObjects, etc.) because their base class, UnityEngine.Object, defines its own operator ==(), operator !=(), & operator bool(). Would it be better to just add a [RequireComponent(typeof(DropArea))] attribute to the class to ensure we have that component before we look for it?
I m glad that you enjoyed the tutorial. Regarding your question, yes, ?? operator can fail quite bad in unity but this happens (afaik) when the game object is during the destroy process but not destoryed yet (you can see that the name of the object is "null") But this should not be the case here as the gameobject is shared between EquipmentSlot and DropComponent and even if the gameobject is during the destroy process and we fail to get the DropComponent it would not matter anymore because the object will be destroyed anyway. But you can also add RequireComponent if you want :D
@@GlassChewer No problem, the videos are done in order to help others with different things in Unity and I m glad to clarify questions about the things presented in the video
@@Noixelfer Hello, it's me again one week later. With this system, I managed to take my inventory system to the next level, tho to work with my pre-existing system my UI's inventory slot hierarchy game object now has the following: ItemSlot script to hold the item DraggableComponent script Canvas - a second canvas so I can adjust the sorting layer Graphics Raycaster - to turns the slot on and off / prevent clicking also, the draggable component always returns to the original position and passes its item to the other slot if it has a drop area and ItemSot However, I have a tiny problem with the rect transform position, its position is not synced, it has something to do with eventData.delta / objectCanvas.scaleFactor but I cant seem to get my head around it and fix it. Do you have any idea about how could I fix this? Thank you again for this tutorial :D
My guess is that maybe the local canvas component might interfere somehow Hierarchy is: UI: Inventory: ItemSlotGroup: Slot (0): here is the drop area and drop actions Border: ItemHolder: here is the draggable component and ItemSlot Text:
With this method, if I drag another object into a box with an object in it, will the object inside return to its place in the menu? Will they switch places? I hope you understand me cause my English is kinda bad
Hello, in the version from this video there is no condition to see if the slot is occupied or not, so you can place multiple objects on the same slot (not the desired scenario) So I've made a little update a while ago, It's the version 1.0.1 github.com/Noixelfer/Drag-DropTutorial/releases/tag/1.0.1 which won't allow you to drop an item on top of another one. A swap or the object inside returning to its place in menu would be good options and I've thought about them, maybe I'll release another version on git with those versions
Thanks a lot , but it shows this error : error CS0246: The type or namespace name 'DropArea' could not be found (are you missing a using directive or an assembly reference?) how can I fix it ?
Make sure that you created the class DropArea. If you created the class DropArea but placed it in a namespace, make sure to write using namespace namespaceName in the script that you want to use the drop area, (replace namespaceName with the namespace from the DropArea) If you still have troubles, please provide more informations (you can also join the discord chanel and there I can provide better support)
I’ve got issue with line 40 in DraggableComponent script 1 Error: The name ‘rectTransform’ does not exist in the current context 2 Error: ‘canvas’ does not exist in the current contex Any Ideas why ?
Make sure that you declared the varialbles like this: private RectTransform rectTransform; private Canvas canvas; You can also check the code on github to see if you've missed anything. Hope that this will help you 😁
So clean! So clean! I LOVE IT!!! Great job!
Thank you for your kind words! I'm really happy that you enjoyed the tutorial 😁
Thank you very much for this tutorial Kindly Implement this Drag and Drop system using raycast
Thank you! Unfortunately I don't plan to do a Drag and Drop tutorial using raycats, at least not for now
I got an anxiety attack seeing you remember so many codes and coding so fast.
Sorry and thank you 😅. I was like that too a couple of years ago but now it feels like second nature
UA-cam is the real world haha.
Keep up the good work friend. You defo put a huge smile on my face...
Thank you for your kind message, I m glad my video helped you :D
Thank you for sharing this helpful tutorial!
I have a question, how can you swap any item in inventory with other item?
This is very very nice tutorial. I am beginner in programming, but this tutorial makes my inventory running so smooth. :D
Ty so much for your feedback, I'm glad that it is working well in your project
Very nice tutorial. Thanks for making this.
You're welcome! :D
amazing technic..thank you
I follow this method but don't know how to make reset button
Hello Johan, I'm happy that you enjoyed the video. Do you mean reset button like reset the last move or reset all the items to the initial position?
@@Noixelfer yes like that, back to their initial position. Can you give some direction
@@johanalmansyah6140 Now, it depends very much on your implementation. But you can do the following thing: In the EquipmentSlot class write a function that clears the slot: pastebin.com/5WZrBEse (the indentation got quite messy in the pastebin) And then all you need to do is to go trough all the slots and call ClearSlot method on each of them and then you could run the initialization method again. This is a hacky and quick way to resolve your issue and a more proper one is in function of your implementation of the inventory and the way you use it. A better approach might be to keep a reference to the initial drop area in the DraggableComponent and have a Reset function which takes the DraggableComponent back to the initial drop area
Hi, thanks for this tutorial !
I got one question: How to make the current dragged object above of all of others objects ?
When i use your sample and replace the "f" transparent image with a no transparent image, i got this issue...
For example, the apple dragged from the "Gauntels" container to another container like "Greaves", the apple is not always on top if you move it onto from "Gauntels" to "Greaves" and vice-verse
Thanks for your answer !
Thanks, this was very helpful but what about dragging the item from the equipment slot back to inventory?
Hello Kunz, I'm happy to hear that you found the video helpful. As for dragging the item back to the inventory, it was a common request from the users and so I did a release with this feature on github, the link is here: github.com/Noixelfer/Drag-DropTutorial/releases/tag/1.0.1
@@Noixelfer amazing thanks so much!
@@kunz4164 You're welcome 😁
@@Noixelfer I've been killing my head trying to solve the issue of double equipping, you are a life savior brother, thank you!
Awesome ty! :D
You're welcome! :D
Great Tutorial, but how to forbid to add 2 items more in the same slot?
Oh, i forgot to cover that. You creat a DisableDrop condition which derives from DropCondition and in the Check method you always return false. Then you add it to the dropArea when an item is dropped.
@@Noixelfer idk how to write it in C# - I'm very noobie :( Could you be more specifik?
@@a.d.6985 @Kiriakos41 @
KratosunBaltasınaSapOlanAdam Sorry for the late reply for this request. I've been planning a second part on this system for a while but it seems that I don't find the time to do it right now, so I've updated the github repository with the bug fixed (you can no longer drop 2 items on the same slot). The link is here github.com/Noixelfer/Drag-DropTutorial/releases/tag/1.0.1 if it has any problems or you have any questions regarding the changes in the code, feel free to ask me and I will answer (you can contact me on discord too). Hope that it helps you all, if you have any other sugestions I would be more than glad to hear them
This is the only one that worked of all the tutorials, thank you. Also, how do i make the item return to the original spot and can move to any other slot?
I m glad it worked for you. As regarding to your question (as i have seen is a pretty popular request) I will do a part 2 video where i will add those features as it a bit much to explain in a comment. I will try to release the video as soon as possible
Hey I know this is a little of a stretch, I am trying to implement the system but what is happening is the following: I drag a weapon to the slot, then try adding another one to the same slot, goes back to inventory so thats working fine. BUt then when i remove the original weapon from the slot and try to drag it again to the equipment slot, it goes back to the inventory. Do you know what could be causing the issue?
Hello. Did you tried to do it with the bow? cause I looked into the project and the bow was bugged (it has some extra components). Also, the bow does not have the weaon component attached so it can't go into the weapon slot. Also, make sure to use the latest release at it had a couple of fixes after the video was release, you can find it here: github.com/Noixelfer/Drag-DropTutorial/releases/tag/1.0.2
Thanks a lot, you made it very easy to understand. I just have one question regarding the EquipmentSlot class and ?? operator. I had no idea about this operator so I googled it and it seems that it's not very reliable while using it with UnityEngine.Object derivatives (GameObjects, Components, MonoBehaviours, ScriptableObjects, etc.) because their base class, UnityEngine.Object, defines its own operator ==(), operator !=(), & operator bool(). Would it be better to just add a [RequireComponent(typeof(DropArea))] attribute to the class to ensure we have that component before we look for it?
I m glad that you enjoyed the tutorial. Regarding your question, yes, ?? operator can fail quite bad in unity but this happens (afaik) when the game object is during the destroy process but not destoryed yet (you can see that the name of the object is "null") But this should not be the case here as the gameobject is shared between EquipmentSlot and DropComponent and even if the gameobject is during the destroy process and we fail to get the DropComponent it would not matter anymore because the object will be destroyed anyway. But you can also add RequireComponent if you want :D
@@Noixelfer Cool! Thank you for taking the time to explain this as well!
@@GlassChewer No problem, the videos are done in order to help others with different things in Unity and I m glad to clarify questions about the things presented in the video
@@Noixelfer Hello, it's me again one week later. With this system, I managed to take my inventory system to the next level, tho to work with my pre-existing system my UI's inventory slot hierarchy game object now has the following:
ItemSlot script to hold the item
DraggableComponent script
Canvas - a second canvas so I can adjust the sorting layer
Graphics Raycaster - to turns the slot on and off / prevent clicking
also, the draggable component always returns to the original position and passes its item to the other slot if it has a drop area and ItemSot
However, I have a tiny problem with the rect transform position, its position is not synced, it has something to do with eventData.delta / objectCanvas.scaleFactor but I cant seem to get my head around it and fix it. Do you have any idea about how could I fix this?
Thank you again for this tutorial :D
My guess is that maybe the local canvas component might interfere somehow
Hierarchy is:
UI:
Inventory:
ItemSlotGroup:
Slot (0): here is the drop area and drop actions
Border:
ItemHolder: here is the draggable component and ItemSlot
Text:
With this method, if I drag another object into a box with an object in it, will the object inside return to its place in the menu? Will they switch places? I hope you understand me cause my English is kinda bad
Hello, in the version from this video there is no condition to see if the slot is occupied or not, so you can place multiple objects on the same slot (not the desired scenario) So I've made a little update a while ago, It's the version 1.0.1 github.com/Noixelfer/Drag-DropTutorial/releases/tag/1.0.1 which won't allow you to drop an item on top of another one. A swap or the object inside returning to its place in menu would be good options and I've thought about them, maybe I'll release another version on git with those versions
@@Noixelfer i think it can be really useful. Thank you so much for answering
@@sedaerkmen6691 I'm glad that I was able to help you 😁
Thanks a lot , but it shows this error :
error CS0246: The type or namespace name 'DropArea' could not be found (are you missing a using directive or an assembly reference?)
how can I fix it ?
Make sure that you created the class DropArea. If you created the class DropArea but placed it in a namespace, make sure to write using namespace namespaceName in the script that you want to use the drop area, (replace namespaceName with the namespace from the DropArea) If you still have troubles, please provide more informations (you can also join the discord chanel and there I can provide better support)
Be sure to add using System;
Have i missed that one? usually i hit Alt + Enter to quickly add stuff like that.
@@Noixelfer alt enter works too
I’ve got issue with line 40 in DraggableComponent script
1 Error: The name ‘rectTransform’ does not exist in the current context
2 Error: ‘canvas’ does not exist in the current contex
Any Ideas why ?
Make sure that you declared the varialbles like this:
private RectTransform rectTransform;
private Canvas canvas;
You can also check the code on github to see if you've missed anything. Hope that this will help you 😁
@@Noixelfer Hmmm... resolve but I get more errors. I take your source code and seems all right. Thanks for quick reply.
@@maciejbrzezinski3273 I'm glad that I was able to help you ☺️
I have no clue what's going on. My Visual Studio says Action missing namespace. its all fucked.
Did you declared using System;?
@@Noixelfer yes. I have all the packets youhave in the tut.
@@MindGem Then join the discord channel and I will be able to help you when I get home, in about 6 hours
Will this work in mobile?
Yes, it should work on mobile
I Drag Handler XD
Thx bro