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:
- Animators are a component that can take an AnimatorController.
- The AnimatorController is this state machine machine with states and transitions.
- The AnimatorController, however, is only a definition, and thus, is an asset file.
- 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.
- 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:
- Query the state of my Bolt graphs during runtime, and
- Execute a graph from a C# script at runtime,
I’d like to know:
-
Does a FlowMachine always instantiate a “runtime clone” like Animators instantiate RuntimeAnimatorControllers of their own?
-
What’s the difference between a FlowMachine’s graph, graphData, and DefaultGraph() in the Scripting API?
-
How do I see which state__s__ are active on a currently-running state graph (StateMachine and/or StateMacro)?
-
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);
}
}