NodeCanvas Forums › Support › [BUG] Node became "detached" and doubling, when Unity Editor window lost focus
Hey!
I’m trying to switch from GOAP to NodeCanvas, and faced with some strange issue…
Here is the screen capture instead long description – https://cl.ly/0v0G3u2T0T3g
So, to reproduce them you need to:
1. create a sample BT
2. save scene and relaunch Unity (this step can be dropped, cause it just to get “clean” results)
3. open Canvas window and select any node
4. switch to another application (or make Unity Editor window lost focus)
5. switch back
As you can see the node appears at different position, and it lost connection to parent node, and now it .
6. Try to repeat step #4, but now don’t select any nodes.
As you can see now a new (previously selected node) is just added to canvas.
It feels like it just copy/pasted after step #4.
Unfortunately, this makes impossible to work with NodeCanvas for me now 🙁
Can you please suggest me any solution for this issue?
PS. It is more like feedback, not a bug, but navigation window (at bottom right) is painful.
PPS. But overall – I believe that NodeCanvas is exactly what I looking for 😉
A small update.
Looks like this issue appears only if mouse cursor is at Canvas Window space.
Also forget to mention, I’m using the latest Unity version on macOS.
Hello and sorry for the late reply (I was ill).
This is super weird. Under Windows OS this does not happen at all (on any Unity version), so this has to be a MacOS thing but it’s still very weird that this happens at all :(. I can’t think of any reasons why the node is being moved or even duplicated simply by switch apps.
I will try find any part of the code that might be responsible for this.
Thanks for the report.
Join us on Discord: https://discord.gg/97q2Rjh
Hey! Hope you are OK now!
I have a filling that this topic is somehow related to my issue too.
I see that you have attached a package there, I’ll try it tomorrow.
The exact same thing is happening to me. I wrote you an email thread a while ago …
Hope you can get it fixed somehow, we’ve invested a lot of time in writing upgrades for NodeCanvas for multilanguage dialogs and now this is a very annoying blocker :/ …
Here’s a stack trace of what gets called when the node is duplicated (or rather pasted) on switching back to unity:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
DUPLICATED UnityEngine.Debug:Log(Object) NodeCanvas.DialogueTrees.MotivitiLocSay:OnValidate(Graph) (at Assets/NodeCanvas-I2Localization-master/unity-project/Assets/NodeCanvas Integrations/I2 Localization/Nodes/MotivitiLocSay.cs:146) NodeCanvas.Framework.Node:Duplicate(Graph) (at Assets/ParadoxNotion/NodeCanvas/Framework/Runtime/Graphs/Node.cs:241) NodeCanvas.Framework.Graph:CloneNodes(List1, Graph, Vector2) (at Assets/ParadoxNotion/NodeCanvas/Framework/Runtime/Graphs/Graph.cs:435) NodeCanvas.Editor.GraphEditor:TryPasteNodesInGraph(Graph, Node[], Vector2) (at Assets/ParadoxNotion/NodeCanvas/Framework/Design/Editor/Windows/GraphEditor_Events.cs:173) NodeCanvas.Editor.GraphEditor:HandlePostNodesGraphEvents(Graph, Vector2) (at Assets/ParadoxNotion/NodeCanvas/Framework/Design/Editor/Windows/GraphEditor_Events.cs:86) NodeCanvas.Editor.GraphEditor:OnGUI() (at Assets/ParadoxNotion/NodeCanvas/Framework/Design/Editor/Windows/GraphEditor.cs:528) UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr) Ending up here (in our custom code): public override void OnValidate(Graph assignedGraph) { System.Diagnostics.StackTrace stackTrace = new System.Diagnostics.StackTrace(); if (stackTrace.GetFrame(1).GetMethod().Name == "Duplicate") //gets the name of the method, that called OnValidate(). because, only Duplicate() must trigger next code { Debug.Log("DUPLICATED"); wasDuplicated = true; completeID = null; completeID = GetId(); UpdateEnglishText(); } base.OnValidate(assignedGraph); } |
Again, for clarification, here’s the NodeCanvas code that gets called on macOS that shouldn’t be called when cmd+tabbing back to Unity.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
///Graph events AFTER nodes static void HandlePostNodesGraphEvents(Graph graph, Vector2 canvasMousePos){ //Shortcuts if (GUIUtility.keyboardControl == 0){ //Copy/Cut/Paste if (e.type == EventType.ValidateCommand || e.type == EventType.Used){ if (e.commandName == "Copy" || e.commandName == "Cut"){ List<Node> selection = null; if (GraphEditorUtility.activeNode != null){ selection = new List<Node>{GraphEditorUtility.activeNode}; } if (GraphEditorUtility.activeElements != null && GraphEditorUtility.activeElements.Count > 0){ selection = GraphEditorUtility.activeElements.Cast<Node>().ToList(); } if (selection != null){ CopyBuffer.Set<Node[]>( Graph.CloneNodes(selection).ToArray() ); if (e.commandName == "Cut"){ foreach (Node node in selection){ graph.RemoveNode(node); } } } e.Use(); } if (e.commandName == "Paste"){ if (CopyBuffer.Has<Node[]>()){ // TADEJ: we end up here but we shouldn't when switching back to Unity on macOS TryPasteNodesInGraph(graph, CopyBuffer.Get<Node[]>(), canvasMousePos + new Vector2(500,500) / graph.zoomFactor ); } e.Use(); } } |
Any news here? 🙂
Hello again,
I am feeling better now. Thank you!
Can you please try and change the following in the code you’ve posted and let me know if the problem persists?
Please change this line:
if (e.type == EventType.ValidateCommand || e.type == EventType.Used){
To this:
if (e.type == EventType.ValidateCommand){
(thus removing the EventType.Used check)
Please let me know.
Thank you!
Join us on Discord: https://discord.gg/97q2Rjh
Hi again!
Good to hear you’re feeling better!
Unfortunately no: https://www.dropbox.com/s/tcx6n5r16327q91/nodecanvas-issue-03052018.mov?dl=0
-Tadej
The version below seems to work better, although I get this issue:
ArgumentException: Getting control 0’s position in a group with only 0 controls when doing Repaint
Aborting
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
if (GUIUtility.keyboardControl == 0){ if (e.type == EventType.ValidateCommand) { e.Use(); } //Copy/Cut/Paste if (e.type == EventType.ExecuteCommand/* || e.type == EventType.Used*/){ if (e.commandName == "Copy" || e.commandName == "Cut"){ List<Node> selection = null; if (GraphEditorUtility.activeNode != null){ selection = new List<Node>{GraphEditorUtility.activeNode}; } if (GraphEditorUtility.activeElements != null && GraphEditorUtility.activeElements.Count > 0){ selection = GraphEditorUtility.activeElements.Cast<Node>().ToList(); } if (selection != null){ CopyBuffer.Set<Node[]>( Graph.CloneNodes(selection).ToArray() ); if (e.commandName == "Cut"){ foreach (Node node in selection){ graph.RemoveNode(node); } } } // e.Use(); } if (e.commandName == "Paste"){ if (CopyBuffer.Has<Node[]>()){ TryPasteNodesInGraph(graph, CopyBuffer.Get<Node[]>(), canvasMousePos + new Vector2(500,500) / graph.zoomFactor ); } // e.Use(); } } |
Hello again,
Thanks for the follow up.
This is so weird. I think that I might just as well remove the copy/paste shortcuts from MAC considering that (at least in the way I’ve implemented) they impose such a big problem and I don’t really understand why that is the case as of yet :(.
I do some more tests before deciding to do so though.
Thanks again for the information provided and of course for the problem found.
Join us on Discord: https://discord.gg/97q2Rjh
Looking at the documentation for ValidateEvent:
https://docs.unity3d.com/ScriptReference/EventType.ValidateCommand.html
Is it possible that this is the intended behaviour and it just happens to work fine on Windows?
I haven’t really dug into it very deeply so sorry for speculating.
Anyway, the above fix seems to work pretty well for me so far.
Hey,
Thanks for the follow up and sorry for the late reply.
Unfortunately this is not the first and only differences between Win and Mac OS regarding the Unity’s UI and event system that have occurred to me thus far. ContextClick is another “inconsistent” event type between Win and Mac that I remember for example, and sometimes workarounds are needed to make them work in both OS.
I will check your posted fix on Windows and if it does not create an issue in Windows as well, then I might just as well implement your fix, considering it is working under Mac. 🙂
Thank you!
Join us on Discord: https://discord.gg/97q2Rjh