Search Unity

Set graph of flow machine

Discussion in 'Visual Scripting' started by votinc, Feb 4, 2021.

  1. votinc

    votinc

    Joined:
    Dec 18, 2020
    Posts:
    1
    Hello,

    I've set up an graph in which I create a new game object. Now I want this game object to have a predefined flow graph. I've added a flow machine to the object with the "add component"-element and it works, but I can't find an element like "flow machine set graph" or "flow machine set flow macro". Do I have to make changes to the unit options? Or how can I attach a predefined flow macro to the flow machine of the object?

    Hope u can help me.
     
  2. ericb_unity

    ericb_unity

    Unity Technologies

    Joined:
    Nov 24, 2017
    Posts:
    167
    At the moment Bolt have nothing to change the flow graph asset in a flow machine. We have a task to fix this.

    Until we get nodes integrated in a new release, you can add this script in your project.


    For Bolt 1.4.13(from the asset store)
    • Create a new c# script in your project named: TempFlowMachineNodes
    • Copy and past the code below and save the script.
    Code (CSharp):
    1. using Bolt;
    2. using Ludiq;
    3. using UnityEngine;
    4.  
    5. [IncludeInSettings(true)]
    6. public static class TempFlowMachineNodes
    7. {
    8.     public static void AddFlowMachineComponent(GameObject gameObject, FlowMacro flowMacro)
    9.     {
    10.      
    11.         gameObject.AddComponent<FlowMachine>().nest.SwitchToMacro(flowMacro);
    12.     }
    13.  
    14.     public static void SetFlowGraph(object goOrFlowMachine, FlowMacro flowGraph)
    15.     {
    16.         if (goOrFlowMachine is GameObject go)
    17.         {
    18.             go.GetComponent<FlowMachine>().nest.SwitchToMacro(flowGraph);
    19.         }
    20.         else if (goOrFlowMachine is FlowMachine flo)
    21.         {
    22.             flo.nest.SwitchToMacro(flowGraph);
    23.         }
    24.     }
    25. }
    • Click on Tools -> Bolt -> Build Unit Options
      upload_2021-2-4_16-9-12.png
    • Now in your graph you will be able to find the SetFlowGraph node to swap your graph asset. You can link a game object or a flow machine component to it. The Game Object will only interact on the first flow machine component.
      upload_2021-2-4_16-11-48.png

      Example use case.
      upload_2021-2-4_20-52-39.png
     
    iLyxa3D likes this.
  3. the_chole_

    the_chole_

    Joined:
    Jul 11, 2021
    Posts:
    1
    do you have a version for bolt 1.4.15 ?
     
  4. PanthenEye

    PanthenEye

    Joined:
    Oct 14, 2013
    Posts:
    2,076
    1.4.13 and 1.4.15 have identical API so this solution should also work for the latest version of Bolt.