Comments (6)
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.
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.
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.
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.
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.
Cool that you've found a solution:)
from node_editor_framework.
Related Issues (20)
- The connections will miss when I add a new node. HOT 2
- GUIScaleUtility.cs Init Method NullReferenceException in Unity 2019.1.2f1 HOT 10
- Insane Bug from using RTEditorGUI.EnumPopup() HOT 3
- XML not saving node values HOT 10
- Is Project Active and Package Support? HOT 15
- `PlayModeStateChange' could not be found. Are you missing a using directive or an assembly reference? HOT 3
- [Solved] Context menu not showing up. HOT 2
- Multiple instances of node editors open at once HOT 1
- Toolbar is not showing up HOT 4
- All data is lost when I change the scene, even though I have extra saved as an asset file HOT 4
- How to input multiple outputs to a node? HOT 8
- Apple M1 computers not displaying Bezier curves HOT 3
- Added one node. Then it stoped working. (Remove the node, re-install, sitll not working) Unity 2020.2 LTS
- Implementation of a Logic Graph HOT 7
- XML import issue on UWP
- I deleted the ScriptableObjects in Assets/DefaultEditorResources/Node_Editor_Framework HOT 3
- Making children of node drag along with parent HOT 5
- Functional Nodes that are not tied to the Node Editor Window HOT 6
- Loading canvas based on Selection.activeTransform? HOT 4
- seems undo pro doesnt work with unity 2022.2.8 not sure what version it stopped working at HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from node_editor_framework.