- Home /
DragAndDrop class bugged?
Hi,
I'm trying to use the drag and drop functionality of the UnityEditor classes. I had a piece of code that worked fine yesterday, but today it does not work anymore. I haven't changed ANYTHING:
if (Event.current.type == EventType.MouseDown && Event.current.button == 0) {
this.__draggedSection = sections[i];
DragAndDrop.PrepareStartDrag();
DragAndDrop.StartDrag("Dragging section");
Event.current.Use();
}
if (this.__draggedSection != null && Event.current.type == EventType.DragUpdated) {
DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
Event.current.Use();
}
if (this.__draggedSection != null && Event.current.type == EventType.DragPerform) {
DragAndDrop.AcceptDrag();
/*if (GUILayoutUtility.GetLastRect().Contains(Event.current.mousePosition) && this.__draggedSection != sections[i]) {
sections[i].ConnectFrom(this.__draggedSection);
this.__draggedSection.ConnectTo(sections[i], sections[i].tiles[0]);
}*/
this.__draggedSection = null;
Event.current.Use();
}
So today I opened Unity, opened the EditorWindow this was in and the drag and drop functionalities all were gone. Also some other weird stuff was going on. The MouseDown event was bugged; When I pressed the mouse, the MouseDown event was not triggered untill I released my mousebutton (a MouseUp event). Also whenever I was dragging, the DragUpdated event was never fired. When I removed the lines
DragAndDrop.PrepareStartDrag();
DragAndDrop.StartDrag("Dragging section");
The MouseDown event was behaving as normal again, but the drag functionality did not work anymore. I'm aware that I can just use regular mouse events, but I'd like to see this DragAndDrop class work properly (also because I can just easily change the cursor while dragging). Anybody encoutered this before? I work on Windows 7 Profesional, Unity 3.5.
Thanks!
I know it's old, but I have the same issue with Unity 4.1. This morning, all my drag and drop decide to stop working. If I comment StartDrag(), everything goes back to normal - expect the drag and drop behavior.
All the Event stop firing as long as StartDrag is around. Worst, the whole UI of Unity appear to be frozen in time. Other windows just stop refreshing.
Answer by s0ulboy05 · May 22, 2014 at 10:33 AM
Before calling StartDrag (and after PrepareStartDrag) try assigning something to the field DragAndDrop.objectReferences. For me it worked this code:
DragAndDrop.objectReferences = new UnityEngine.Object[0];