Search Unity

Question Can subgraphs in a flow be hotswapped to another 'generic' subgraph?

Discussion in 'Visual Scripting' started by ForgottenDreamcat, Oct 4, 2022.

  1. ForgottenDreamcat

    ForgottenDreamcat

    Joined:
    Aug 26, 2022
    Posts:
    17
    I have a graph with a flow. A subgraph is connected as part of the flow. Is it possible to dynamically swap (hotswap) out that subgraph to a different subgraph asset or that another object holds, without me needing to know the subgraph target ahead of time?

    I'm new to Visual Scripting, and I'm not yet familiar with the nodes and workflow (I never used Bolt). Most videos seem to cover either the basics or other random conversions from normal scripts.
     
  2. REDACT3D_

    REDACT3D_

    Joined:
    Nov 8, 2020
    Posts:
    222
    Lookin for this node?
    Capture.PNG
    you would need to know them ahead of time.. but not sure what you mean
     
  3. PanthenEye

    PanthenEye

    Joined:
    Oct 14, 2013
    Posts:
    2,073
    I don't think this is possible. Technically custom events can pass around any object but there are no equivalent of a delegate in visual scripting. What you see in the graph, is what you get, it's all pretty static.
     
    ForgottenDreamcat likes this.
  4. ericb_unity

    ericb_unity

    Unity Technologies

    Joined:
    Nov 24, 2017
    Posts:
    167
    If you are talking about swapping a subgraph node that is connected inside of a graph, it may not possible the way you describe it, without special work in C#.

    If you want to swap graphs directly within the component, what REDACT3D_ showed will do it.

    The other option could be to use events nodes.
     
    ForgottenDreamcat likes this.
  5. ForgottenDreamcat

    ForgottenDreamcat

    Joined:
    Aug 26, 2022
    Posts:
    17
    This is most unfortunate, because if it were possible, VS would be an amazing solution for quite a few problems.

    I have a scenario where I would like to, for the ease of coding workflow, loop through logic normally, but when I encounter a specific scenario, I can hit a button and hotswap the subgraph from one that 'does nothing' (is a simple passthrough from Input to Output node) to one based on whatever I am targeting.

    I'm currently using an asynchronous loop to drive some logic, and being able to hotswap to another routine without stopping the loop would have been a really elegant solution with a graph hotswap.

    I can do this with another solution, like xNode, because I can extend from the graph with an interface that has an awaitable function and then provide the async prefix in the derived definition.

    Thank you guys, I think I will use a simpler solution to my problem... it is just unfortunate that I'll have to wait until VS is a bit more feature-rich and considers supporting such a feature in the future!
     
  6. PanthenEye

    PanthenEye

    Joined:
    Oct 14, 2013
    Posts:
    2,073
    Perhaps a custom node can be written that takes in an abstract class as an input, the node then simply executes the abstract class' implementation. Regular Inspector supports abstract classes via [SerializeReference] for different configurations accessible to a designer, but it's unlikely to be supported in graphs directly.
     
  7. ForgottenDreamcat

    ForgottenDreamcat

    Joined:
    Aug 26, 2022
    Posts:
    17
    I had considered doing this, but I don't know how to call the ports of a graph within a script?

    I think that is where I was looking to see if it were possible and delved a little into the baseclasses 'Graph' and 'FlowGraph' but was not sure if I was looking for the wrong thing, or if I need to look for a 'Flow' component, or something.

    Or, is it possible for me to define functions for that abstract class within a graph?

    If either of those are possible, then it might still be doable... or maybe there is another way...

    Sorry, just trying to catch up with your line of thinking! Because I would very-much like to try out UVS :3

    --

    Edit: Basically, I was hoping to use UVS to design the logic for certain things and then reuse the graph assets if I want to do similar actions.

    If I'm defining the logic in the abstract class, it kinda defeats the goal I want to achieve with utilizing UVS for the logic design
     
  8. PanthenEye

    PanthenEye

    Joined:
    Oct 14, 2013
    Posts:
    2,073
    Yea, data workflows like that are not really feasible right now. They're working on that however. In a couple of years they'll have a new runtime with a new API, and they'll swap current IMGUI UI implementation to UI Toolkit based Graph Tools Foundation framework so API on extending the node functionality on editor level will also change. They're also working on many other fundamental changes. It'll take a few years by the looks of it though. Can't really tell, there's no ETA given which implies it's at least two years away by my guess. Amongst the many improvements constructing graphs purely in code has also been mentioned.
     
    ForgottenDreamcat likes this.