Search Unity

Question Is there a scriptable way to automate adding Visual Scripting nodes to a Script Graph?

Discussion in 'Visual Scripting' started by dave-mona, Feb 3, 2023.

  1. dave-mona

    dave-mona

    Joined:
    Sep 19, 2022
    Posts:
    3
    Context:

    Unity Web GL builds (so IL2CPP) with third-party asset bundles (e.g. these are made by folks using our platform).

    The asset bundle authors don't have access to pure C# so we're using Visual Scripting for some things.

    Need the AOT Stubs generated so they don't get stripped from the build.

    Current solution is to manually add these to a "dummy" visual script graph by hand. This is time consuming and error prone. Looking for an automated way to make this workaround "manageable."

    Here's an example we're currently doing by hand (works). Don't even need to link them for the AOT Stubs:
    upload_2023-2-3_14-54-9.png
     
  2. PanthenEye

    PanthenEye

    Joined:
    Oct 14, 2013
    Posts:
    2,076
    As far as I'm aware, until the next major version of the tool drops in 2-3 years, this is the only option.
     
  3. dave-mona

    dave-mona

    Joined:
    Sep 19, 2022
    Posts:
    3
    I was afraid that you (specifically you!) would say that. :(

    Thank you for everything you do in the Visual Scripting forums @PanthenEye . You're a legend!
     
    PanthenEye likes this.
  4. PanthenEye

    PanthenEye

    Joined:
    Oct 14, 2013
    Posts:
    2,076
    Perhaps you could look into how Node Finder does its search and build something on top of that mechanism to crawl all your graphs, cache any unique nodes found, then somehow create a graph asset and fill it with those nodes, but none of this is documented in the manual. Have to reverse engineer from package source.
     
    dave-mona likes this.
  5. termway

    termway

    Joined:
    Jul 5, 2012
    Posts:
    84
    I'm not sure if I understand yours need correctly, but you can automate the creation of the nodes and connections of a ScriptMachine.

    Code (CSharp):
    1. // Adds a unit to a graph
    2. OnEnable onEnableUnit = new OnEnable()
    3. {
    4.     position = new Vector2(0, 0),
    5. };
    6. scriptMachine.graph.units.Add(onEnableUnit);
    7.  
    8. // Adds a flow connection between two node of a graph (ControlOutput -> ControlInput)
    9. scriptMachine.graph.controlConnections.Add(new ControlConnection(onEnableUnit.trigger, XXXunit.enter));
    10.  
    11. // Adds a value connection between two nodes of a graph (ValueOutput -> ValueInput)
    12. scriptMachine.graph.valueConnections.Add(new ValueConnection(XXXunit.result, YYYunit.inputValue));
    13. // or use the valueOutputs & valueInputs property of a unit.
    for literal node you can take a look at this thread:
    https://forum.unity.com/threads/code-to-programmatically-add-a-literal-node-to-a-flow-graph.1410876/
     
    Yuze_75 and PanthenEye like this.