#Using visual scripting in edit mode

1 messages · Page 1 of 1 (latest)

burnt ice
#

Most of my code base is made in vanilla C# script. But for some part, I want to use Visual Scripting to allow collaboration with C# beginner collegues. I have a custom inspector that has a button to quickly call a function from editor.

This function raise a CustomEvent to interact with Graphs, and it works well while in play mode. But during edit mode, the CustomEvent isn't processed. We are working on Unity 6.1, is there a way to enable edit mode

stuck forge
pliant prairie
# burnt ice Most of my code base is made in vanilla C# script. But for some part, I want to ...

You can use this custom Unit, you will have to add the ManualEvent unit to the project then the ManualEventWidget to a Editor folder then regenerate the units which is in, Edit > Project Settings > Visual Scripting > Regenerate Units.

Then it should add a unit that has a button on it you can press that to trigger the flow in edit mode or play mode.

In the Fuzzy Finder you can go to Events > Editor you should see the ManualEvent there or you can search for it.

Here is the ManualEventWidget script:

stuck forge
pliant prairie
burnt ice
pliant prairie
# burnt ice As I understand it, this add a button widget to trigger the graph from the graph...

Oh so you don't want to trigger the graph from inside, you want to trigger from a Script? If so yes you can use

Flow.New(GraphReference).Run(TargetPort)

To get the graph reference just access the ScriptMachine component or the ScriptGraphAsset which you can use

machine.GetReference().AsReference()
asset.GetReference().AsReference()

then you will need to find the unit you want and get the controloutput port and pass that Into .Run()

#

So you would need to do something like this, which would fine the first CustomEvent and trigger it

ScriptMachine machine = GetComponent<ScriptMachine>();
var reference = machine.GetReference().AsReference();
foreach (var unit in machine.graph.units)
{
    if (unit is CustomEvent customEvent)
    {                               
         Flow.New(reference).Run(customEvent.trigger);
         break;
     }
}
burnt ice
#

Oh right that seems promising. I'll look the documentation further about customEvent parameters, thanks for pointing out the right direction. I'll let you know how it went later, when I get to try it

burnt ice
#

I updated my helper a bit to be able to run any Graph from its input node :

public static void RunGraph(ScriptMachine scriptMachine, ScriptGraphAsset asset, object argValue)
{
    GraphReference graphReference = GraphReference.New(asset, scriptMachine.gameObject);
    
    var input = graphReference.graph.elements.OfType<GraphInput>().First();
    ValueOutput unitOutputPort = input.valueOutputs.First();
    // Set the valueOutput to argValue or set graph InputData
    Flow.New(graphReference).Run(input.controlOutputs.First());
}

But I don't understand how I can set the Data Inputs. I've used Variables.Graph as a workaround, but i feel this is a clanky way to input data. The Visual Scripting API is quite explainationfree when it comes to how classes works. I assume I have to use GraphData to setup my GraphData 🤔