Siccity / xNode

Unity Node Editor: Lets you view and edit node graphs inside Unity
MIT License
3.34k stars 591 forks source link

DynamicPortList gui doesn't update correctly when changing its content. #117

Open ChadKeating opened 5 years ago

ChadKeating commented 5 years ago

When setting the content of an instancePortList - that has been previously populated - the port list gui won't update.

The culprit in this case I believe is a private field: NodeEditorGUILayout.reorderableListCache If you clear or remove the node you update from this list then the gui will be updated.

XNode.Node example:

        [Input(instancePortList = true)]
        public string[] inputs;

        [Output(instancePortList = true)]
        public string[] outputs;

        public void ChangeContent() //Call this from an editor script
        {
            ClearInstancePorts();
            inputs = new []{ "test1", "test2" };
            outputs = new []{ "test1", "test2" };
        }

This is a second issue that could be related but perhaps it needs it's own issue ticket. Assuming the above issue is fixed or there is a method to force the cache to update:

Calling IncreaseContent will display gui ports: "test1", "test2", "test3", "test4" Then calling ReduceContent will change the displayed gui ports to: "test5", "test6", "test6", "test6" This also then breaks the node for any further use and changes via the + and - controls in the editor gui throw null arguement and index out of bounds exceptions.

XNode.Node example:

        [Input(instancePortList = true)]
        public string[] inputs;

        [Output(instancePortList = true)]
        public string[] outputs;

        public void IncreaseContent() //Call this from an editor script
        {
            inputs = new []{ "test1", "test2", "test3", "test4" };
            outputs = new []{ "test1", "test2", "test3", "test4" };
        }

        public void ReduceContent() //Call this from an editor script
        {
            inputs = new []{ "test5", "test6" };
            outputs = new []{ "test5", "test6" };
        }
Siccity commented 5 years ago

I made some changes to InstancePortList. Might be worth checking if it solves your issues.

Siccity commented 5 years ago

Seems like there's some deeper rooted issues. Just having two dynamic port lists on one node causes a lot of issues.

ChadKeating commented 5 years ago

Sorry for a late response, I havent worked on this part of our project in a while.

I updated xNode in our project today and the port lists still arent getting updated correctly. We do have multiple dynamic lists for both input and output.

As a workaround, we are just using NodeEditorGUILayout.reorderableListCache.Clear(); before updating any lists.