#Drag & Drop
1 messages · Page 1 of 1 (latest)
Smart
after you click and it disappears, can you double click on it in the hierarchy and see what its values for its position are
When in game
i think the issue is with it being in world space
the tutorial you're following is supposed to be for a normal canvas
take a screenshot of it
try with camera space or overlay
i guess i make a new canvas for that
cause the click manager worked pretty good set up like that
no harm right?
yes just right click -> UI -> Canvas
don't set it to world space and put the same script and give it the same children
this is the set up of the canvas for the tutorial
✅ Get the Project files and Utilities at https://unitycodemonkey.com/video.php?v=BGr-7GZJNXg
Let's make a very simple Drag and Drop in Unity, great for an Inventory System.
Simple Inventory System in Unity (Store, Use, Stack and Drop Items)
https://www.youtube.com/watch?v=2WnAOV7nHW0
If you have any questions post them in the comments and I'll...
the one you're following
Really most of this stuff should be using the built-in interfaces for Events, IDragHandler would be appropriate, and hell, there's even some suspiciously okay looking example code
https://docs.unity3d.com/Packages/com.unity.ugui@1.0/api/UnityEngine.EventSystems.IDragHandler.html
Though, if you're following a tutorial it might be best to stick to how they're getting it done.
It seems odd the way you're moving things to and from canvases?
it uses idraghandler
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
but now on that canvas it doesnt do anything at all
What's the object you're clicking on look like?
What's Task Button?
yea that the sprite i just realized was unnecessary
now it looks like this BUT when i remove the sprite
Does it work now it's set up like this?
That width and height seems really really small but I'm unsure whether that'd affect anything
they are invisible when not in pause but they do show up and in the right spot
probably wrong position or sorting order.
yea its sorting order im now looking up how to change that. I only know how to do it with sprites there is just a "sorting order" option
the canvas has a setting
ah jesus
select one of them and check the position
Your camera may be hiding the UI layer?
oh look at the video when i pause the game and it changes from the game screen to the scene view they do show and they show in the correct position
What are their Z positions
i tested with 0 and -1
actually select and take a screenshot.
the camera is -10
They should all have z as 0
Can you check your camera isn't excluding the UI layer from rendering
Also, that's world space, not UI space
so that actually seems wrong
i tried with different layer
Also this:
if the canvas is ScreenSpace Overlay and you're drawing stuff at ~(-400, -250) That is not going to be on the screen
I imagine 1-1.5 pixels won't show very well
it is not pixels but units
Well, I'm sorry to tell you, but it is in pixels.
At least if you are using screen space canvas
wtf
I think I'm gonna stop here. Because it feels like it's going no where. Do your learning of the ui system, follow the tutorial exactly as it is and make sure it works. Only then attempt making changes.
I am not trying to make changes
Yeah. You're trying to use some steps from the tutorial in a different context. That's even worse. At least if you're not understanding what you're doing.
I mean u are saying its pixels and i am sure u know what you are talking about but it did show up properly before with width 2 and height 1
i could see it and click t
it
the drag&drop behaved weirdly but it was not 2x1 pixels
and now you are acting like I am crazy to expect to see a 2x1 pixel image when it showed up perfect before
and no alternative
Probably when the canvas was in world space right?
i can make it bigger i tried
it did not show it just was huge
yes
it is huge in the scene but does not show in game either
Well, then reread my message again. I said it's in pixels with what canvas?
Did you also fix the negative position?
ok
now wiht 0 0 0
and 200x100 it shows
alright
still got issues but this is the first progress in 4 hours 😅
oh btw thanks alot for all of your time I am very grateful
ok drag&drop works which is nice but it always spawns at the bottom left
never out of screen or somewhere else
always the pivot at the outermost bottom left corner
As you were told before, you'll need to spawn in in screen space position, not world space.
GameObject result = Instantiate(mathTask, rbody.position, Quaternion.identity);
so in here instead of the value of the rigidbody position is my guess
is that was screen space is? they always stay at the same screen position?
@flint terrace is that what the screen space camera is?
Screen space is that the positions are in screen coordinates
you see in the video the mathTasks stays put on the screen
Yes
that is inherently its behavior when the canvas is in screen space?
If you don't move something in screen coordinates, yes, it stays still on the screen
damnit
of course I dont want that
so all this trying to get "screen space" to work
was just a waste
I want it to be in the world
damn
You can still make it stay in the same world position if you move it in script.🤷♂️
I don't even have close to an idea how to do that
it feels like that object shouldnt be on a screen space canvas
Not that hard if you learn properly.
But I can agree with that.
It should've been a sprite renderer + collider in the first place. I've no clue why you decided to get involved with canvases
because of the textMeshPro element it needs a canvas
so my initial attempt wasn't even off using a sprite with a small world canvas for the textmeshpro I just need a different drag&drop solution?
Yes. In case I'm wrong, you might still need a canvas for tmp and will need to sync it's position with the sprite in world space.
The generic Text Mesh Pro text doesn't need a canvas and is just a mesh in world-space
Ah, so there is one
If you're looking to switch this to world space you'd want to look for examples with 2D physics that have drag and drop behaviours
I'm sure Melv has one
Somewhere in these examples https://github.com/Unity-Technologies/PhysicsExamples2D, I believe many of them use a drag and drop script
https://github.com/Unity-Technologies/PhysicsExamples2D/blob/master/Assets/Scripts/Generic/DragTarget.cs