Search Unity

  1. If you have experience with import & exporting custom (.unitypackage) packages, please help complete a survey (open until May 15, 2024).
    Dismiss Notice
  2. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice

Run Visual Script from code and get return value

Discussion in 'Visual Scripting' started by sdebaun_unity, May 12, 2021.

  1. sdebaun_unity

    sdebaun_unity

    Joined:
    Mar 12, 2021
    Posts:
    5
    (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:

    Code (CSharp):
    1. public class Foo : extends 3PartyThing.BaseClass // which extends monobehavior
    2. {
    3.   // flowmachine because i want it to manage its own state via variables in a scene
    4.   [SerializeField] public FlowMachine targetFlow; // attached to a gameobject in a scene
    5.  
    6.   // 3p asset calls this and relies on the int returned to decide what to do
    7.   public void overload int OverloadedFunctionWithReturnValue
    8.   {
    9.     // obviously this isn't the right code, but is it even possible?
    10.     targetFlow.Invoke()
    11.     return targetFlow.valueOutput
    12.   }
    13. }
    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
     
    io-games and Peter-Chen like this.
  2. Neodrop

    Neodrop

    Joined:
    Oct 24, 2008
    Posts:
    1,359
    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