Seneral / Node_Editor_Framework

A flexible and modular Node Editor Framework for creating node based displays and editors in Unity
https://nodeeditor.seneral.dev
MIT License
2.01k stars 414 forks source link

The connections will miss when I add a new node. #181

Closed QppisTc closed 5 years ago

QppisTc commented 5 years ago

When I add a node,and click "Save canvas". it's look perfect.But if I switch a scene or click play button, and open this canvas, the connections of nodes will all missed. I check the canvas's asset in text mode. The SerializeField _connections is missed. SLEPA}SER22M0%%LUXIO$8M

Seneral commented 5 years ago

Have verified it, seems I have gotten something wrong while implementing undo (which also required a small change in how caching worked). Working in a fix right now, sorry about that.

Seneral commented 5 years ago

Ok so I found the main cause. To make clear what was happening and the new behaviour I have decided, I'll outline the problem here.

The problem occurs when you add nodes, and then load a new scene without clicking outside the window. Clicking outside the window before saving allows the node editor to add the new nodes to the cache. By skipping that, all changes you did since the last cache save are lost (after last time clicking away from the window or last automatic cache save). This has been the case previously, as the cache itself was a working copy.

Now in the last update (undo), I added the separate, faster, not crash-resistant cache, which is essentially just a dump of the current ScriptableObjects into a file (this is the requirement of the Undo system). Again, they are not designed to be crash save, for that we still have the proper working copy cache in regular intervals. The problem is, if you add new nodes, but not let the cache system add them to the cache, it will create inconsistencies. The other nodes and canvas link to a node that only exist in memory until the next cache (click outside the window). If now a new scene loads, those inconsistencies will break the canvas.

I had intended for the lastSession (the proper, crash-save cache) to load if curSession (SO dump cache) has insonsistencies. For whatever reason I didn't fully implement that, so in those cases where the dump would break (cache, or interrupted without save - currently only switching scenes) it would try to load the broken canvas. Now I've added detection for that and delete the dump cache if it is found to be faulty, and a warning displayed.

Note that, even before last update (undo), this behaviour would just silently load the old lastSession and you would silently loose your work if you didn't give it a chance to save before switching scenes. Only now I even have a method to detect if work is lost, so I added the warning. The amount of work we're talking about here is the work you've done after last clicking out of the window or the last auto-save (defined in NodeEditorUserCache.cacheIntervalSec, default 60 seconds). Will update in a few minutes