alelievr / NodeGraphProcessor

Node graph editor framework focused on data processing using Unity UIElements and C# 4.6
https://github.com/alelievr/NodeGraphProcessor/projects/2
MIT License
2.28k stars 379 forks source link

Undo break dynamic output #203

Open fractalisstudio opened 2 years ago

fractalisstudio commented 2 years ago

When doing Undo command i lose most of my outputs edges on my custom nodes (on any graph). Am pretty sure my code is the issue (my method may be outdated) but just and case i will post a issues.

Here how most of my dynamic outputs are done

    public virtual IEnumerable<PortData> ListPortBehavior(List<SerializableEdge> edges)
    {
        int outputPortCount = Mathf.Max(1, edges.Count + 1);

        for (int i = 0; i < outputPortCount; i++)
        {
            yield return new PortData
            {
                displayName = "child " + i,
                displayType = typeof(BehaviorTreeLink),
                identifier = i.ToString(), // Must be unique
                vertical = true,
            };
        }
    }

And and class NodeView i do

    //Work around
    public override void Enable()
    {
        nodeTarget.onAfterEdgeConnected += OnStructuralChange;
        nodeTarget.onAfterEdgeDisconnected += OnStructuralChange;
    }

    void OnStructuralChange(SerializableEdge _) => ForceUpdatePorts();