Comments (4)
NodeEditor window uses NodeEditorUserCache to store the currently open instance, so you'd have to access that.
Take control over it and you directly edit what the opened canvas is and what it's save and cache behaviour is.
You should be able to get the currently open window (or open one) with GetWindow(); and access the cache as the canvasCache member. All following edits are called on this object.
So, if these canvases live in the scene, it could work nicely. Set useCache to false and call SetCanvas, and the window should switch to editing it next time it redraws (which will set the curNodeCanvas, that is really only for the time frame when it is drawn, e.g. multiple windows can draw one after another, setting their canvas as current while drawing.).
If your canvases are assets (so not instances), you do not want to edit them directly, that might at best result in inconsistent files, and at worst break completely due to how ScriptableObjects are handled. Generally when you load a canvas from assets, it copies it into an instance in memory to prevent weirdness from unity.
So if they are assets, set(keep) useCache to true and call LoadNodeCanvas(string path) on it. If you have the reference, you can either get the path from it's savePath property (should be correct afaik), or you can call SetCanvas with CreateWorkingCopy(nodeCanvas) called on it before.
In both cases you also need to save before switching away from it, since you'd be working on copies, not the original.
You can of course just try setting it with SetCanvas without the working copy, but don't expect it to work, or if it does, that it's reliable.
from node_editor_framework.
My canvases do live in the scene so it should be a simple solution. I'm a little confused how to set useCache to false when it is a private field, I've tried setting the 'CACHE' custom directive in the player settings, but I am still getting a exception: Couldn't add object to asset file because the MonoBehaviour 'simple' is already an asset at 'Assets/MyTrees/simple.asset'!
. It seems like if useCache was false, this wouldn't be an issue, but it gets set to true in the constructor and I can't modify it from my SelectionLoader script
from node_editor_framework.
My bad, didn't notice that. Been a while since I wrote that code.
You can set the variable nodeCanvas.livesInScene or hardcode the property nodeCanvas.allowSceneSaveOnly to at least influence WHERE it will store the cache working copy (here, in the scene, instead of as an asset).
After you call SetCanvas it SHOULD update the source nodeCanvas.savePath to "SCENE/lastSession" or something, but it should otherwise directly work on the canvas.
It will also now have a entry in the scene of that canvas, so it will automatically load a COPY of that canvas, stored as "SCENE/lastSession", the next time you open the editor window up.
To prevent this, usually useCache should be set, but ofc the interface wasn't designed with changing that without modification in mind unfortunately. Alternatively, you can call "userCache.DeleteCache" or directly "NodeEditorSaveManager.DeleteSceneNodeCanvas ("lastSession")".
Hopefully that works. Do note I work off of memory here.
from node_editor_framework.
Coming back to this issue, I've found that userCache.LoadNodeCanvas is the method I was looking for. I've included my script which will find the corresponding node canvas attached to my gameobject and set the displayed node canvas to that. Note that it's specific to my project, so a lot of it is unnecessary, but it's enough to understand I think.
Here is a pastebin link if the formatting is bad: https://pastebin.com/F1i8T1Z3
using UnityEngine;
using UnityEditor;
using NodeEditorFramework;
using NodeEditorFramework.Utilities;
namespace NodeEditorFramework.Standard
{
[ExecuteInEditMode]
public class SelectionLoader : MonoBehaviour
{
[HideInInspector]
public Transform activeTree;
public NodeEditorUserCache canvasCache;
// Update is called once per frame
void Update()
{
Transform trans = Selection.activeTransform;
if (trans != null)
{
if (trans.TryGetComponent<BehaviorTreeManager>(out BehaviorTreeManager manager))
{
if (NodeEditor.curNodeCanvas != null && manager.behaviorTree != null)
{
string loadedCanvasName = NodeEditor.curNodeCanvas.saveName;
int index = manager.behaviorTree.name.IndexOf("(Clone)");
string btName = null;
if (index > -1)
btName = manager.behaviorTree.name.Substring(0, index);
else
btName = manager.behaviorTree.name;
if(loadedCanvasName.Equals(btName))
{
activeTree = trans;
// update statuses
((BehaviorTreeCanvas)NodeEditor.curNodeCanvas).rootNode.RecursivelyCopyStatus(manager.behaviorTree.rootNode);
} else
{
// set canvas to manager.behaviorTree
if (canvasCache != null)
{
canvasCache.SaveCache();
canvasCache.LoadNodeCanvas("Assets/MyTrees/" + btName + ".asset");
}
}
}
}
}
}
}
}
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
- 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.