Run Visual Script from code and get return value

(I am aware of CustomEvents and use them a bunch but don’t see how they could solve this use case, because I need the return value)

A third party asset requires me to inherit from their base classes to extend their system. One of the methods I must overload has to have a return value that the underlying system relies on.

I’d like to be able to do something like:

public class Foo : extends 3PartyThing.BaseClass // which extends monobehavior
{
  // flowmachine because i want it to manage its own state via variables in a scene
  [SerializeField] public FlowMachine targetFlow; // attached to a gameobject in a scene

  // 3p asset calls this and relies on the int returned to decide what to do
  public void overload int OverloadedFunctionWithReturnValue
  {
    // obviously this isn't the right code, but is it even possible?
    targetFlow.Invoke()
    return targetFlow.valueOutput
  }
}

With the goal that I can have a generic class that I use with the third party asset, and then just link it to different flowmachines wherever I use it, and keep my domain logic in visual scripts. With the idea that I could design those visual scripts like SuperUnits, having an Input and Output node.

I found a couple threads that sort of reference calling visual scripts from code, but they dont cover this. I’ve written a bunch of debug code and plodded through the collections and methods for Flow, FlowGraph, GraphReference, but don’t see a way to do this. The API docs are… underwhelmingly informative.

Is this possible? Any ideas? Am I missing something that makes this impossible?

sd

2 Likes

Hello!
You can send CustomEvent with some custome parameter (any your class instance for example) and fill this instance with returned data inside the bolt graph