Bolt Visual Scripting - How/Where are these Graphs Running?

I have a sort of large question.

I’m coming with a Unity Animator background. This is an analogy (and feel free to correct me if I’m wrong). As you probably know:

  1. Animators are a component that can take an AnimatorController.
  2. The AnimatorController is this state machine machine with states and transitions.
  3. The AnimatorController, however, is only a definition, and thus, is an asset file.
  4. When an Animator wants to start playing (based on an AnimatorController), it somehow creates a RuntimeAnimatorController, which is the actually-playing state machine at runtime for 1 GameObject hierarchy.
  5. The Animator does NOT run the AnimatorController directly, because if you have 6 characters with Animators, they’ll need 6 state machines playing through different states at the same time – they need to remember their own state – despite using the same AnimatorController definition.

In Bolt, a graph/state machine is either a FlowMacro or a StateMacro (this is like an AnimatorController).
The component in the scene is either a FlowMachine or a StateMachine (this is like an Animator component).

Because I want to:

  1. Query the state of my Bolt graphs during runtime, and
  2. Execute a graph from a C# script at runtime,

I’d like to know:

  1. Does a FlowMachine always instantiate a “runtime clone” like Animators instantiate RuntimeAnimatorControllers of their own?

  2. What’s the difference between a FlowMachine’s graph, graphData, and DefaultGraph() in the Scripting API?

  3. How do I see which state__s__ are active on a currently-running state graph (StateMachine and/or StateMacro)?

  4. I saw that I can use GraphReference.New(IGraphRoot, bool);. I show an example of its use in the code below. What does this do, and why would we ever want to use this?

See the code snippet below for an example of what I’m asking about, hopefully this helps:

using UnityEngine;
using Ludiq;
using Bolt;

public class Tester : MonoBehaviour {
    [SerializeField] private FlowMachine flowMachine;
    [SerializeField] private StateMachine stateMachine;
   
    private void Start() {
        //2. Difference between the following?
        //        - flowMachine.graph
        //        - flowMachine.graphData
        //        - flowMachine.DefaultGraph()
       
        foreach (IState state in stateMachine.graph.states) {
            //3. Can I see if state is active here?
        }
       
        //4. What is this?
        GraphReference g = GraphReference.New(flowMachine, true);
    }
}

Since state machines are infinitely nestable (see super states), there’s no built-in way of seeing the currently active state. You’d have to roll something on your own in the state graphs such as having a bool per each state.

The rest of the questions are too technical for me, so someone more knowledgeable on the secrets of Bolt 1 API needs to come around and answer them for you.

1 Like

@PanthenEye Ah, interesting…

Thanks for the insight! :slight_smile:

Hi @ModLunar ! Any news about this? Have you succeed in getting the active state through code?

Thanks for asking!
Unfortunately I didn’t find anything too encouraging.

The codebase wasn’t well-documented, so I ended up not using Visual Scripting for a while.
I wonder if it’s changed though?

I vaguely remember you could create your own state information in the graph itself, and query that using … events was it?

Unfortunately it seems it is not possible to do it in direct way, so we will change our system (is not a complicated change) to avoid enable/disable game objects.

1 Like