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
2k stars 415 forks source link

Make NodeEditorSaveManager.CreateWorkingCopy() Work at runtime. #160

Closed jangofett890 closed 6 years ago

jangofett890 commented 6 years ago

I needed to create an instance of a slightly modified DialogNodeCanvas for my game, and I tried using UnityEngine.Object.Instantiate but it only made a new Canvas and the nodes were still a reference.

I found out about NodeEditorSaveManager.CreateWorkingCopy() and it would not execute at runtime because the dictionaries of NodeTypes and NodePortDeclerations were empty. I fixed this by calling their two recalculate functions in CreateWorkingCopy().

The new code: `

       public static NodeCanvas CreateWorkingCopy (NodeCanvas nodeCanvas, bool editorStates = true) 
        {
        if (nodeCanvas == null) {
            return null;
        }

        NodeTypes.FetchNodeTypes();
        ConnectionPortManager.FetchNodeConnectionDeclarations();
        //.... Cut code here

`

Seneral commented 6 years ago

Sorry for the late answer. Although not explicitly stated, the framework generally expects a call to NodeEditor.checkInit before usage. If you only use stuff like that, you can just pass false, which will init the base modules. If you want to use GUI parts of the framework, call this additionally with parameter true from a GUI function (!) and it will init the GUI-related modules. Hope that helps!