Coder Social home page Coder Social logo

Comments (6)

Seneral avatar Seneral commented on May 20, 2024

Sorry for the late reply. Wasn't able to set up email notifications on my (new) phone yet so I have to learn to manually check emails lol
Anyway, it is easily possible. Just create a new NodeCanvas like you would do with every scriptable object and then populate it with whatever you want using code. After that you can save it if you want. All this should not cause any interferences with the currently loaded canvas:)
Example:

NodeCanvas canvas = ScriptableObject.CreateInstance<NodeCanvas> ();
// Populate canvas with some nodes and stuff
NodeCanvasSaveManager.SaveNodeCanvas ("Assets/CreatedCanvas.asset", canvas, false);

It's pseudocode but it should work. Let me know if you encountered any errors of if I misunderstood you:)

from node_editor_framework.

snarlynarwhal avatar snarlynarwhal commented on May 20, 2024

No worries and thanks! I should have probably elaborated more haha. I want my Duplicate (new canvas) button to:

  • Save the current canvas to the scene
  • Create a new canvas (as if I pressed the new canvas button)
  • Then add duplicate nodes

So the main obstacle is loading the created canvas into the node editor window. Here's what I have so far:

private void DupeNewCanvas() {

            string curCanvasName = NodeEditor.curNodeCanvas.name;

            if (curCanvasName == null || curCanvasName == "" || curCanvasName == "LastSession") {
                Debug.LogError("ERROR: Save to Scene before duplicating a machine to a new canvas.");
            } else {
                NodeEditorSaveManager.SaveSceneNodeCanvas(curCanvasName, ref NodeEditor.curNodeCanvas, true);
                NodeEditor.curNodeCanvas = CreateInstance<NodeCanvas>();
                NodeEditor.curNodeCanvas.name = "New Canvas";
                NodeEditor.curEditorState = CreateInstance<NodeEditorState>();
                NodeEditor.curEditorState.canvas = NodeEditor.curNodeCanvas;
                NodeEditor.curEditorState.name = "MainEditorState";
                NodeEditor.curNodeCanvas.editorStates = new NodeEditorState[] { NodeEditor.curEditorState };
                NodeEditorSaveManager.SaveNodeCanvas("Assets/Editor/Node_Editor/LastSession.asset", NodeEditor.curNodeCanvas, true);
            }
}

This works at emulating clicking "new canvas" but only once. I'm assuming some caching prevents it from working again since clearing that allows me to do it again. If I attempted to create the node right after these lines of code, I get a NodeEditor.curNodeCanvas is null error. I tried delaying the call, but the canvas appears to stay null for some reason.

from node_editor_framework.

Seneral avatar Seneral commented on May 20, 2024

Use NodeEditorWindow.mainNodeCanvas instead!
I will try to emphasize this more, NodeEditorWindow is not strictly part of the framework, more like a default browser to built upon. It is the 'user' of the framework and holds the current canvas.
The framework itself does not hold the canvas - NodeEditor.curNodeCanvas is only assigned while a user - in this case the window - draws the canvas. For the rest of the frame, it is null. This allows multiple 'users' to make use of the framework at the same time:)
Anyway, enough explaining the why. Replacing NodeEditor.curNodeCanvas with NodeEditorWindow.mainNodeCanvas should do it;)

I do have a new update in development which emphasizes this, it is basically a wrapper for holding canvases, called a user. More about it once I commit it:)

from node_editor_framework.

snarlynarwhal avatar snarlynarwhal commented on May 20, 2024

There's no way to access that script from a node, though right? Since it's not an editor script? If not, I'll just add my button else where. :) If I do use say the NodeEditorWindow to add my code, how do I get my node? For example, usually to get the gameobject being displayed by the inspector, you use Selected.activeGameObject. How would I get the active node? I'm pretty new to scriptable objects tbh haha - sorry for my noobness lol.
EDIT: Found a work around that will do for now. Thanks! :)

from node_editor_framework.

Seneral avatar Seneral commented on May 20, 2024

You can try to put your script in an editor folder. Obviously it then won't be able to be used at runtime...
Try Assets/Plugins/Node_Editor/Nodes/Editor and if that doesn't work Assets/Plugins/Editor/Node_Editor/Nodes or similar:)

from node_editor_framework.

Seneral avatar Seneral commented on May 20, 2024

Cool that you've found a solution:)

from node_editor_framework.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.