Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there any way to create an auto-expanding array of ports? #117

Open
masonwheeler opened this issue Jun 5, 2022 · 2 comments
Open

Is there any way to create an auto-expanding array of ports? #117

masonwheeler opened this issue Jun 5, 2022 · 2 comments

Comments

@masonwheeler
Copy link

If you've worked with node graphs in Unity or Unreal, you've probably seen nodes that can take an arbitrary number of inputs, set up so that whenever you connect the last input, it creates a new port. (For example, a Sum node that lets you sum up any number of values.)

Is it possible to do the same thing with NodeNetwork? If so, how do you set it up? (And if not, could it be added?)

@SadE54
Copy link

SadE54 commented Jun 6, 2022

I dit it adding a little plus in the block , and by increasing the outputs vector

@StellarWitch7
Copy link

My project doesn't have nodes that pass values around, but I got the automatic endpoint creation by simply checking occasionally if the amount of connected endpoints was equal to the amount of total endpoints. Here's my code, which is run every second (if there's an event, it should be used, I was just doing this in a hurry).

        private void CheckOutputs()
        {
            int connectedOutputs = 0;

            foreach(var output in this.Outputs.Items)
            {
                if (output.Connections.Count > 0)
                {
                    connectedOutputs++;
                }
            }

            if (connectedOutputs >= this.Outputs.Count)
            {
                CreateNewOutput();
            }
            else if (connectedOutputs < this.Outputs.Count - 1)
            {
                RemoveExtraOutput();
            }
        }

        private void CreateNewOutput()
        {
            var newOutput = new ValueNodeOutputViewModel<bool>()
            {
                Name = "new",
                MaxConnections = 1,
                Value = Observable.Return(true)
            };

            this.Outputs.Add(newOutput);
        }

        private void RemoveExtraOutput()
        {
            var remove = new NodeOutputViewModel();

            foreach (var output in this.Outputs.Items)
            {
                if (output.Connections.Count <= 0)
                {
                    remove = output;
                    break;
                }
            }

            this.Outputs.Remove(remove);
        }

This code is on the custom node view model.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants