How can I implement drag and drop into the scene from my EditorPlugin?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By idbrii

If I have an editor plugin that houses a bunch of scenes, then how can I drag those scenes into the current open scene?

I found some information on drag here and it looks like I can define get_drag_data in my control, but what should it return? Searching through engine code doesn’t return any results for something that looks the FileSystem panel nor does searching for drop_data give anything that looks like a scene editor (viewport seems to only do generic handling).

:bust_in_silhouette: Reply From: idbrii

get_drag_data is correct and you need to return a Dictionary. Looks like CanvasItemEditorViewport::drop_data might be the right handler.

Your Godot 3 code should look like this:

func get_drag_data(position: Vector2):
	return {
		files = [scene_path], # something like "res://assets/truck.tscn"
		type = "files",
	}

The function name is _get_drag_data in Godot 4.

Godot-Instance-Dock is an example Godot 4 plugin using _get_drag_data.

Likely you don’t need set_drag_preview since it’ll just cover up the object when you’re dragging it around the scene.