NodeGraphProcessor icon indicating copy to clipboard operation
NodeGraphProcessor copied to clipboard

Subgraphs /nested graphs

Open andybak opened this issue 3 years ago • 6 comments

I'm still playing and getting to grips with how things work but I suspect eventually I will need subgraphs in some form. I wondered if you'd given the matter much thought or got any rough ideas what the most natural way to approach this would be?

andybak avatar Jul 22 '20 14:07 andybak

Hello,

I actually tried to do it once but I never finished because there were some missing key features to the project. Right now I think you can manage to add a SubGraph node quite easily (the only problem will be serialization I think).

My idea was to create a simple node with a public BaseGraph (serialized with a SerializableObject) and generate the input/output of the nodes using the CustomPortBehavior API from the parameters of the graph (the is an API in the graph to get them). You have both get and set mode on parameters so you can generate both input and outputs.

Finally, in the process function of the node, you can simply process the graph (with a processor in the node).

After this, you can try to do some more complicated things like flattening the subgraph into the current graph before the processing (like unreal blueprint). This allows you to execute only the part of the subgraph you need in case you have multiple outputs.

alelievr avatar Jul 23 '20 17:07 alelievr

I notice one of the to do tasks is "API to create the graph in C#"

Is it currently possible to add nodes from C#? One of the key features for subgraphs is being able to refactor part of an existing graph (select a bunch of nodes and turn it into a subgraph). This would require an API able to create graphs and nodes.

andybak avatar Jul 27 '20 14:07 andybak

Yes it's possible but the API is a bit wonky right now. If you only use the BaseGraphView API it should be fine :) I sugest you to take a look at CreateFromType, you can also find an example here: https://github.com/alelievr/Mixture/blob/mesh-experiments-shipping/Packages/com.alelievr.mixture/Editor/Views/ForStartView.cs#L16

alelievr avatar Jul 27 '20 17:07 alelievr

Hello, is Subgraph coming soon? very need it. Thanks.

EP-Toushirou avatar Jun 09 '21 03:06 EP-Toushirou

Hello, is Subgraph coming soon? very need it. Thanks.

@alelievr , hello, is subgraph can create myself by current api?

EP-Toushirou avatar Jun 26 '21 02:06 EP-Toushirou

Hello @EP-Toushirou

Yes, you can create your own subgraph node. The simplest would be to add a new node that has an object field and accept a BaseGraph in parameter, that way you can mirror the graph parameter (get and set) to the node input and outputs using a CustomPortBehavior.

Then when the node is processed, you need to set the input parameters to the graph, process it, and then copy the output to the output ports of your subgraph node.

I think my implementation will look similar to this when I'll do it but right now I have other priorities to focus on, so not much time to tackle this.

alelievr avatar Jun 26 '21 13:06 alelievr