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

custom output knob loses value upon closing the Node Editor. #154

Closed jangofett890 closed 6 years ago

jangofett890 commented 6 years ago

I have been extending the node editor, trying to get a handle on things and decided to make a simple string input node, however when the editor closes the string value put into the node is lost upon reopening, this does not happen with the float input node and the classes are almost identical.

My node class is here: `

[Node(false, "String/Input")]

public class StringInput : Node {

    public const string ID = "stringInputNode";
    public override string GetID { get { return ID; } }

    public override string Title { get { return "String Input Node"; } }
    public override Vector2 DefaultSize { get { return new Vector2(200, 50); } }

    [ValueConnectionKnob("String Value", Direction.Out, typeof(string))]
    public ValueConnectionKnob outputKnob;

    string value = "";

    public override void NodeGUI() {
        value = RTEditorGUI.TextField(new GUIContent("String : ", "The string to be passed along the output"), value);
        outputKnob.SetPosition();

        if (GUI.changed)
            NodeEditor.curNodeCanvas.OnNodeChange(this);
     }

    public override bool Calculate() {
        outputKnob.SetValue<string>(value);
        return true;
    }

}

`

Quyrean commented 6 years ago

I think you have to put

[SerializeField]

in front of the string because it is private, so

[SerializeField] string value;

I would suggest moving the = "" part to the OnCreate function also.

jangofett890 commented 6 years ago

Ok well that fixed it, I had believed that the value was stored in the Knob itself not in the variables in the node. That wasn't really explained in the Documentation, and the forum thread listed on the site is for general discussion of node editors rather than the framework itself.

Mark this Issue as closed please

Quyrean commented 6 years ago

You have to set the value on the knob to store it there. I think it would be something like this

outputknob.SetValue<string> (value);

However, I think that is a runtime thing and will not be saved with the canvas.

jangofett890 commented 6 years ago

I have that under calculate already in the code provided, changing the string value to public is what fixed it.

Seneral commented 6 years ago

Yes, @Quyrean is correct, knob values are only runtime, storing in the node is the correct way to do this. I didn't think in needed to be put in the docs, but I will consider adding it. Seneral