How To Drag And Drop In Godot - Basic Level Explanation

preview_player
Показать описание
I wish someone had explained the build in drag and drop feature in Godot the way I do it here, so I'm sure there are others who would appreciate it explained in this way as well. It's not very specific, but should be the most adaptable explanation. Enjoy!

Contact and Social Media:

Time Stamps:
00:00 - Intro
00:35 - How To Visualize Back End Dragging And Dropping
01:06 - The Built In Functions Overview
01:55 - Get Drag Data Function Explanation
02:35 - Drag Preview
03:20 - Can Drop Data Function Explanation
04:28 - Drop Data Function Explanation
05:18 - Recap

Music:
Music from Uppbeat:
"I Don't Need Your Love" By Adi Goldstein
License code: NQNGM3R6S374DLJE
Рекомендации по теме
Комментарии
Автор

Update for this tutorial- the functions require underscore now in front of them to work (godot 4 change).
_get_drag_data
_can_drop_data
_drop_data

And instance() is now:
instantiate()

ceruleanserpent
Автор

Hopefully this non-specific explanation will be helpful to a few people. Not sure, but if so I'll try to keep my future Godot videos in this sort of format. :)

Artindi
Автор

Thank you so much for this - I started making things in Godot a couple of weeks ago with no experience with coding. I recently spent two days trying to figure drag and drop out myself (and almost getting there, but the resulting mess was incomprehensible and unpredictable) because all other tutorials focused on RPG-style inventories and textures. Your explanation is high level and easy to transfer to other contexts :)

Unquietrecords
Автор

This is perfect. Exactly what I was looking for. I agree that we need more non-specific examples demonstrating how to approach solving problems in general terms

bryno
Автор

Thanks so much for this. I was lucky that I found this explanation first. The generic approach helped me implement it in my game quickly. In my game, I had to split the code a bit or put the first function in the drag objects and the other two in the drop objects but your explanation mad it easy to determine how to expand to that. Bravo!!!

erobertwald
Автор

Love the little tilt animation and translucency, nice touches.

dandymcgee
Автор

Holy shit ma dude, you actually just provided me the explanation I needed, what a legend

VampireDGames
Автор

This vid helped me a ton in GD3. Found out from switching to GD4 the functions are nearly identical, just add a underscore in front of the func name and the 'position' argument is now 'at_position'.
Ex. func _get_drag_data(at_position):

You'll also see a signal icon pop up for the func if you did it right.

benikeler
Автор

Thank you for making this simple. This was what I was looking for. I can already imagine the many different ways I can sue this.

Lmfaocj
Автор

If you do a search for "Godot drag and drop inventory" there's a bunch of tutorials that cover these functions. Just in case you want more examples of what these could be used for.

KlausWulfenbach
Автор

omg thank you for the nonspecific examples!

PoenariMoon
Автор

Sometimes all you need is something simple, thanks I never knew Godot has a built in function for drag and drop item TwT

bluespider
Автор

Seems like it would be difficult to make something like the olden times gee-whiz Mac OS X dock where the icons grew and shrank and slid around in proximity to the mouse, since control nodes all tend to get a fixed size inside their parent. Might be an interesting experiment.

JavaJack
Автор

One question - how would you store the dictionary made in _get_drag_data on the backend? I want to make a Case of the Golden Idol-inspired detective game: you'll have a set of words that can only be dragged into some slots, depending on their type (e.g. there are verbs, concepts, and names) so the slots will only accept words of a certain type. I can't figure out how to do this - the data dictionary is only accessible in the source node and I don't know how to refer to it in the target node. Would using singletons be the right approach? not sure how to implement that.

Unquietrecords
Автор

Hey man, great video. Do you have any idea how to use get_drag_data but with right click instead?

EnormiE
Автор

What are the 1st lines codes, from the texturebutton Gscript?

Ninjakrom
Автор

Hi.
I'm working on a game in godot, sort of a simple game where you put some cards in order and I'm very new to Godot and i thought that it would be simple to verify if one card is in its correct slot.
For example i have card 8 in slot 5 it there would be a red cross icon, and when you have card 5 in slot 5 you get a green check icon. But with this method I'm guessing you have to verify the texture data because the texture buttons dont actually move. You did mention this when setting minecraft as an example, but I can't figure this out and it took a couple of days until I've given up.
I've tried making the buttons have their own script and trying to verify the path of the texture to be correct but I haven't found resources in the way of trying to make me understand how that is possible.
Anyhow, if you have any idea what i could try I'd be more than happy.
Thank you for the tutorial, very eazy to understand.
Cheers


nvm: figured it out.

aciuvlad
Автор

Great video, but how are you triggering these functions. Every time I drag, the sprite interferes with checking the room for an input event.

TheBiggyJMan
Автор

is it possible to make it so that when I move a slot, its place become empty and the and rest of slots fills it place, to mimic a real drag and drop ??? just like when u edit the home menu of mobile phones ?

neozoid
Автор

can you make a screen panning tutorial?

feedmind