Skip to content
This repository has been archived by the owner on Oct 31, 2023. It is now read-only.

Can no longer save to the scene or load from the scene (get errors) #82

Closed
snarlynarwhal opened this issue Jul 5, 2016 · 31 comments
Closed

Comments

@snarlynarwhal
Copy link

Last week, everything worked perfectly. This morning I opened my project and attempted to load from the scene, then to save to the scene. I got these errors:

image

Any idea what I might have done to break the scene saving/loading or how I might fix this?

@Seneral
Copy link
Owner

Seneral commented Jul 5, 2016

Which version are you using? There seem to be problems with the latest 5.3.5 which I didn't adress yet...

@snarlynarwhal
Copy link
Author

snarlynarwhal commented Jul 5, 2016

I pulled from develop, so the latest. o.0 I needed the save/load to/from scene functionality. D:

I can still test/develop (still can reference scene gameobjects/components) so I'll sit tight until it's fixed. :) Any way I could "refresh" the save data? It doesn't matter if I lose anything (for right now at least).

@Seneral
Copy link
Owner

Seneral commented Jul 5, 2016

Sorry I meant the Unity version 5.3.5:)

@snarlynarwhal
Copy link
Author

snarlynarwhal commented Jul 5, 2016

Oh! Well I have multiple versions of Unity installed, but for this project, I'm using Unity 5.3.4.

@Seneral
Copy link
Owner

Seneral commented Jul 5, 2016

Huh, then this is should not be a problem. Any way you can reproduce it? I am experiencing no problems here... Or maybe I did something to fix it but did not publish yet? 😕

@snarlynarwhal
Copy link
Author

It worked for me for an entire week straight. o.0

I downloaded it on Monday I think, so maybe you fixed it after?

@Seneral
Copy link
Owner

Seneral commented Jul 5, 2016

Nope I did not work on the project too much the past weeks...
Anyway, if I stumble over this error myself I might have a chance to track it down but for me it's currently working:/

@Seneral
Copy link
Owner

Seneral commented Jul 5, 2016

I think it might be triggered if the saved canvas in the entry is null. This is not possible if the canvas is correctly serialized into the scene. It might be related to that atleast, means there is most likely a bug in the seperation of the scene canvases from the asset saves...
Atleast it's a start. But I won't have time for now:(

@snarlynarwhal
Copy link
Author

Okay no worries - I'll look into it and try and figure it out!

@snarlynarwhal
Copy link
Author

My subscribing/unsubscribing to/from delegates stopped working also - might these be related?

@Seneral
Copy link
Owner

Seneral commented Jul 5, 2016

Weird, these are not connected at all - what do you mean with 'stopped working'? There's no hacky code or something like that could break easily, it's simple callback/delegate logic....
Did you change anything? ;)

@snarlynarwhal
Copy link
Author

snarlynarwhal commented Jul 5, 2016

I have the same code, but added a second one:

// Use this for initialization
public void OnEnable() {

    // On add requirement
    NodeEditorCallbacks.OnAddConnection -= OnAddRequirement;
    NodeEditorCallbacks.OnAddConnection += OnAddRequirement;

    // On remove requirement
    NodeEditorCallbacks.OnRemoveConnection -= OnRemoveRequirement;
    NodeEditorCallbacks.OnRemoveConnection += OnRemoveRequirement;
}

It incrementally calls the methods. So it calls it once, than twice, than three times, etc.

@Seneral
Copy link
Owner

Seneral commented Jul 5, 2016

And without it works?
Isn't it called or is an error thrown?

@snarlynarwhal
Copy link
Author

snarlynarwhal commented Jul 5, 2016

Saving/Loading
I went to a new scene and the loading/saving to/from scene worked (this issue caused errors) - one of the hidden components related to the node editor must have gotten corrupt. What would be the best way to "flush" these?

Delegates
Still no luck with delegates though - still trying to fix that. The delegates work in that the code in called and it causes no errors. But, it doesn't appear to be unsubscribing properly since it calls the function more each time. So the first time it calls it once. Then twice. Then three times. And so on.

When I remove the newly added subscription, it still doesn't work even though that same code worked last week (breaks exactly as described above). Maybe the delegates working but another issue is causing it to re-call itself more and more each time?

EDIT: Fixed (delegate issue), I'm dumb.

I figured it out... My bad. Just in-case you're curious, here's what I did:

// On add 
            NodeEditorCallbacks.OnAddConnection -= OnRemoveRequirement; // added this first time on accident and it never got out of the system
            //NodeEditorCallbacks.OnAddConnection -= OnAddRequirement; // correct code - wrote after
            NodeEditorCallbacks.OnAddConnection += OnAddRequirement;

            // On remove requirement
            NodeEditorCallbacks.OnRemoveConnection -= OnAddRequirement; // added this first time on accident and it never got out of the system
            NodeEditorCallbacks.OnRemoveConnection -= OnRemoveRequirement; // correct code - wrote after
            NodeEditorCallbacks.OnRemoveConnection += OnRemoveRequirement;

Sorry for wasting your time. D:

@Seneral
Copy link
Owner

Seneral commented Jul 5, 2016

Alright, good you resolved that:) You're not wasting my time, I'm happy to help you out getting something useful from this project:)

To remove your corrupted saves, although not a fix, replace the first two methods and add the third one in NodeEditorSaveManager (attention pseudo code!):

/// <summary>
/// Gets all existing stored saves in the current scene and returns their names
/// </summary>
public static string[] GetSceneSaves ()
{
    return GetAllSaves ().Select (((NodeCanvasSceneSave save) => save.savedNodeCanvas.name)).ToArray ();
}

/// <summary>
/// Finds a scene save in the current scene with specified name or null if it does not exist
/// </summary>
private static NodeCanvasSceneSave FindSceneSave (string saveName)
{
    return GetAllSaves ().Find ((NodeCanvasSceneSave save) => save.savedNodeCanvas.name == saveName);
}

/// <summary>
/// Flushes corrupted scene saves and returns all others
/// </summary>
private static List<NodeCanvasSceneSave> GetAllSaves ()
{ // TODO: Fix cause of occasionally corrupted saves
    FetchSceneSaveHolder ();
    List<NodeCanvasSceneSave> saves = sceneSaveHolder.GetComponents<NodeCanvasSceneSave> ().ToList ();
    for (int cnt = 0; cnt < saves.Count; cnt++) 
    {
        if (saves[cnt].savedNodeCanvas == null) 
        { 
            saves.RemoveAt (cnt); 
            cnt--; 
            Debug.LogWarning ("Deleted one corrupted scene save!"); 
        }
    }
    return saves;
}

That will do for now until I find a fix for the real cause;)

@snarlynarwhal
Copy link
Author

snarlynarwhal commented Jul 5, 2016

Thank you for that ^^^ ! :D

So.. delegates seem to be acting funky still. Occasionally they start behaving as before or stop working altogether. When I restart Unity, it usually starts working again. It stops working altogether super frequently now.. like OnEnable() won't even be called. o.0

But if OnEnable isn't working, isn't it a Unity related issue?

@Seneral
Copy link
Owner

Seneral commented Jul 5, 2016

That sounds to me like serialization issues...
Where/When do you subscribe to these events, in an editor script, a monobehaviour at runtime, etc. ?
And if OnEnable isn't called than it's something other out of the frameworks boundaries I suppose:/ Still no problem to ask if you need help;)

@snarlynarwhal
Copy link
Author

So it seems that it's breaking after each compile. I'm subscribing to the events in an editor script on enable (I unsubscribe, then subscribe as not to have duplicate subscriptions. I'm Googling and it appears a couple of others have had similar issues, but I haven't seem to find a solution yet. :(

@Seneral
Copy link
Owner

Seneral commented Jul 5, 2016

Ok then it's a common problem of Unity... Re-Serialization, which occurs on recompilation, always wipes out unserializable data. This means delegates are usually unsubscribed, too.
There are really very few things you can do against it unfortunately due to the lack of serialization callbacks in Unity 😠

@snarlynarwhal
Copy link
Author

snarlynarwhal commented Jul 5, 2016

Uh oh:

"This is a bug in 5.3.4p4+. It's not fixed yet (as of 5.3.5p2)."

Looks like it might be a Unity bug like you said:
http://forum.unity3d.com/threads/any-error-in-code-any-makes-all-custom-editor-scripts-disappear.408124/

I'm going to try and jump back to before 5.3.4.

@Seneral
Copy link
Owner

Seneral commented Jul 5, 2016

I mean I developed a solution for serializable delegates but still these callbacks are stored as static variables in NodeEditorCallbackReceiver and thus have no chance of being properly serialized and restored...
So the easiest fix would be on your side to recurrently resubscribe (dirty but I have currently few other ideas)

@Seneral
Copy link
Owner

Seneral commented Jul 5, 2016

It's not straight a Unity bug, serialization is a normal process. Just unitys fault for not providing a good interface/API to handle this 😠
But where does it say above sentence?
It has always been a problem with Unity:/

@snarlynarwhal
Copy link
Author

Forgive my lack of understanding, but what exactly do you mean by recurrently resubscribe?

@Seneral
Copy link
Owner

Seneral commented Jul 5, 2016

I thought of doing the process of unsubscribing and resubscribing in Update so you can be sure it is subscribed. It's dirty but my brain's currently too tired to do better:P

Because the initial problem you got is that when a re-serialization is performed, your subscriptions are wiped. So this would make sure it is always subscribed, and always only one instance:)

@snarlynarwhal
Copy link
Author

So I ended up making a class that extended NodeEditorCallbackReceiver and it's working SOO much better for me lol. No weird delegate issues, no editor scripts randomly not working, no DestroyImmediate issues...

New question: Any way to deleted Canvases saved to the scene? It's bugging me have old debug canvases just sitting there lol.

@Votrubec
Copy link

Votrubec commented Jul 6, 2016

My next task was to include the Delete option for assets saved to the Scene. I've got leftover scene assets littering the scene. I was also thinking of saving the nodes themselves to .asset files as well. Interested in hearing progress anyone makes with this if I don't get around to sorting out first.


From: PJ Legendre <notifications@github.commailto:notifications@github.com>
Sent: Wednesday, July 6, 2016 10:03 AM
Subject: Re: [Baste-RainGames/Node_Editor] Can no longer save to the scene or load from the scene (get errors) (#82)
To: Baste-RainGames/Node_Editor <node_editor@noreply.github.commailto:node_editor@noreply.github.com>

So I ended up making a class that extended NodeEditorCallbackReceiver and it's working SOO much better for me lol. No weird delegate issues, no editor scripts randomly not working, no DestroyImmediate issues...

New question: Any way to deleted Canvases saved to the scene? It's bugging me have old debug canvases just sitting there lol.

You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHubhttps://github.com//issues/82#issuecomment-230637790, or mute the threadhttps://github.com/notifications/unsubscribe/AGl2CA2LpnuKtJzXCu4-DMRTk3zn2Q9-ks5qSvDFgaJpZM4JFN_o.

@Seneral
Copy link
Owner

Seneral commented Jul 6, 2016

@pi3butcher Good solution, if thats possible for you :)

Yes I haven't implemented a GUI option for this. It's theoretially easy, there is a save object holding all canvases as components... simply delete the component (by code, as it's invisible, or change hideFlags).
But initially I planned to completely reorder the GUI to fit into a toolbar at the top, so you'd have dropdowns of 'File/' to save/load, 'Edit/' with clutter and options, etc. :D
I delayed it until it would be implemented but yet found not much time to do so, because I also have other bugs to check and fix... I'll have holidays next week so it'll get better for me to work on this:)

@Seneral
Copy link
Owner

Seneral commented Jul 6, 2016

@Votrubec If you'dbe willing to implement it (not necessarily with the whole GUI but would be easie in the long run) that'd be great:)
But what do you mean with 'saving nodes themselves to .asset files as well'? You can't make these assets if the nodes are in a scene file... Why would you want to do this?

@Votrubec
Copy link

Votrubec commented Jul 6, 2016

I'll certainly have a crack at doing it properly. As for the "why?"... I recently implemented an Inventory system that used one Scriptable Object to store a List<> of Items. And each Item was it's own Scriptable Object. These were saved to the file system as individual files, just as the Canvas can be saved to its own asset and the Last Session canvas is stored as its own asset file.

Taking this further, I wanted the option to store the Nodes themselves as individual asset files. It just felt a little "safer" to me, and version control just picks up the asset files so there's no extra work needed there. The Item Scriptable Objects were easy to tweak individually if needed, without going through the custom editor window.

I have a very visual designer colleague who has filled the Scene with test canvases until he got used to saving the Canvas to File instead of to the Scene. At the moment, there was no way for him to delete these discarded canvases. I updated the Node and created the custom ConnectionType to allow the designer to add and remove "evolution paths" and the number of paths from each Node without him having to touch any code (and yes, the Node size grows and shrinks correctly with the number of Output Knobs ;) ). From that point, I was wanting him to be able to grab any Node .asset file of his choosing from the Project Window and drop it into the Inspector fields I set up for individual Nodes. And there you have it, Robert's your mother's brother, or Bob's you uncle, either way, the visual designer can design away to his hearts content.

After all of that, I was wanting to take a look at the zooming feature. It seems that sometimes the Node content get's stuck in an incorrect zoom state, so the content sometimes looks like it's a smaller size, but zoomed and blurred to be the current size. The image shows the problem if you look REALLY closely. The Nodes on the left of the Canvas, in particular the wording "Previous" is blurred. The Nodes on the right of the Canvas, the content is crisp and not zoomed.

nodeeditor

@Seneral
Copy link
Owner

Seneral commented Jul 6, 2016

Sorry for the late reply, just came back from a horrible trip from the new forums, need some rest to cool down 😞

If you want to have control over the nodes, it's not too hard. First of, they are already technically stored as single assets, just as (hidden) subassets. If you go into NodeEditorSaveManager.cs you see in the apropriate functions that

  1. All elements (nodes, knobs) that are scriptableObjects and need to be saved are flagged with Hide (look out for Hideflags)
  2. They are saved by attaching to the main canvas (AddObjectToAsset).
    I recommend you to first comment out the lines of 1.) to get an idea of what's happening and then you can modify the behaviour of 2.) so it's saved alongside the asset rather than as a subasset. It's not too hard given you're a bit familar with AssetDatabase, if you need help, I might be able to provide a sample:)
    Similar goes for the scene saving, theres the FetchSceneSaveHolder method at the top in NodeEditorSaveManager.cs. In it you see the same line of 1.) above where the scene save holder is hidden. Instead of commenting clear the hideflags to make sure the object is made visible again in your existing scenes. Similar for asset saving, a re-save is required to make subassets visible:)

Regarding the zooming glitch, that's a known problem but is out of our reach. It's related to Unity's crappy implementation of zooming support (which also required a hell lot of extra hacking work to do to get it properly working, see GUIScaleUtility):/

@Seneral
Copy link
Owner

Seneral commented Aug 20, 2016

Any updates on this? Don't hesitate to reopen, but I'll just close for now:)

@Seneral Seneral closed this as completed Aug 20, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants