Skip to content

[Api] Graph Evaluator

CoffeeVampir3 edited this page Apr 11, 2021 · 16 revisions
public partial class GraphEvaluator

For usage documentation see Graph Evaluator Usage

Graph Evaluator

Graph Evaluator provides a convenient way to walk through your graph at runtime. It provides the editor-linking capabilites allowing you to visualize your graph as it runs.

public GraphBlueprint graphBlueprint;

This is designed to be easily used by dragging and dropping the any graph blueprint reference in, but hey do what makes you happy.

public void Initialize(Action blackboardInitialization = null)
{
    virtualizedGraph = graphBlueprint.CreateVirtualGraph();
    rootContext = new Context(graphBlueprint.rootNode, virtualizedGraph);
    Reset();
    Blackboards.virtGraph = virtualizedGraph;
    blackboardInitialization?.Invoke();
}

Initializes this Evaluator, as you can see, this creates a virtual graph which the evaluator will use from this point forward. If you try calling evaluate without first having Initialized you will get a null reference exception. You can also setup the initial state of a local blackboard, see Blackboards

public RuntimeNode Step()
{
//...
    nextNode = currentNode.Evaluate(rootContext);
    return nextNode;
//...
}

Steps the graph forward one step and returns the node it's going to evaluate next. If there's no next node, it will pop the top of the Context stack, and will only return null once theirs no next node and nothing on top of the context.

public RuntimeNode Current => currentNode;
public RuntimeNode Next => nextNode;
public RuntimeNode Prev => previousNode;

At any point if you'd like to query which nodes are relevant to the Evaluator, these are the nodes which are being tracked by it.

public void Reset()
{
    currentNode = graphBlueprint.rootNode;
    nextNode = null;
    previousNode = null;
//...
}

Resets this graph so it will begin execution from the root again. If this is called in the editor and a graph is linked, it will also reset the state of the linked graph back to it's initial values.