Siccity / xNode

Unity Node Editor: Lets you view and edit node graphs inside Unity
MIT License
3.21k stars 566 forks source link

References to Node Graphs in Scene Graph are all gone #372

Open FancifulEight opened 10 months ago

FancifulEight commented 10 months ago

I entered Unity's Safe Mode to fix some errors and when I returned to normal operations all references to graphs went missing.

Where do the ScriptableObject NodeGraphs get saved when created by the SceneGraph? If I could find that, that would solve all my problems.

FancifulEight commented 10 months ago

After some digging it seems XNode uses ScriptableObject.CreateInstance() and nothing else, which shouldn't save to disk... So how have I worked on these for several months without encountering this problem?

FancifulEight commented 10 months ago

In order for this to not happen again, I have added AssetDatabase.CreateAsset() to the SceneGraph CreateGraph() function.

        public void CreateGraph(Type type) {
            Undo.RecordObject(sceneGraph, "Create graph");
            sceneGraph.graph = ScriptableObject.CreateInstance(type) as NodeGraph;
            sceneGraph.graph.name = sceneGraph.name + "-graph";
            AssetDatabase.CreateAsset(
                sceneGraph.graph, 
                string.Format(
                    "Assets/DialogueTrees/{0}/{1}.asset", 
                    (sceneGraph.transform.parent == null) ? "None":((sceneGraph.transform.parent.parent == null) ? "None":sceneGraph.transform.parent.parent.name), 
                    sceneGraph.graph.name)
                );
        }
tommardis commented 4 months ago

I think I might be having the same issue, @FancifulEight

When I add a scene graph component to a gameobject, it does still show the "new graph" button, which works, and then the open and remove graph buttons, but when I added my xNode code to another project, it also shows the "script" and "graph" fields for some reason. And if I create a scene graph, then leave and reopen the scene, the scene graph is empty and it's showing the "new graph" button again.

The strange thing is that it's still working fine in my other project! I though it might be the differing Unity version or that I included XNode through github in my newer one, but when I changed them both to match the working project, it was still doing the same thing! Was this the same issue you were having?