Hi, I’ve got this behavior when I leave Dialogue Editor window with Dialoge Node dragging → Mouse Up → go to editor window → Mouse Down → it snaps last dialoge node to mouse position.
I’ve tried to utilize MouseLeaveWindow event, but with no luck.
Any ideas how to fix it?
Unfortunately, there’s not a great solution for this. From the description of the OnMouseLeaveWindow documentation, the event is only called when the mouse leaves the window “without any buttons held down”.
Actually, I just tried to recreate this on my end and am NOT getting this. When the mouse leaves the window, the dialogue stops and is only re-aquired if I hold on to the mouse the whole time before re-entering the window.
Paste in your DialogueEditor.cs and we’ll take a look.
I think the code that would prevent this from being an issue, but it won’t be introduced for another few lectures.
Update: I plugged your code into the DialogueEditor, and was still unable to duplicate the results… This may be an issue with the Unity version itself. You might consider upgrading to the latest LTS version of Unity 2020.
While OnMouseLeaveWindow only fires if no buttons are pressed (annoying that they did that, but I believe it’s to facilitate dragging from one window to another), you can always test the position of the mouse against the bounds of the window, which is stored in a field position.
So
if (!position.Contains(Event.current.mousePosition))
{
draggingNode = null;
return;
}
should automatically reset draggingNode if the mouse leaves the boundary of the EditorWindow.
Thank you. It almost works :).
Event.current.mousePosition gives you mouse position in relation to the window position so you need to add it to the eqaution.
if (!position.Contains(Event.current.mousePosition + position.position))
{
draggingNode = null;
return;
}