Execute graph
Last updated
Last updated
A Logic graph can be executed directly from the DataObject (not scene dependent) or from the LogicController component (scene dependent).
If your graph has component references, you'll have to execute the graph from the LogicController component. Otherwise, nodes that need those references won't find them.
The Following code executes the graph above directly:
Direct execution also allows you to execute graphs in your custom DataObject classes.
The LogicController lets you assign a graph to a game object. A graph executed from the LogicController component runs as a unique instance in the scene. Therefore you can have multiple graph instances in a scene each running a copy of the same graph.
When using component references in a graph you will have to run the graph by a LogicController component to make sure you can assign the references.
Simply assign the LogicController component from the Unity inspector to a GameObject. Assign the DataLibrary and select the graph asset.
You can manually start an execution from the LogicController. Simply uncheck the option: Execute on start.
The return value node lets you return a value to the OnComplete event.
Execute the graph and get the returning result:
You can also call custom methods on the graph OnComplete event by using Unity Events. Create a method which takes the GraphData.GraphProcessingResult parameter and assign it to the Unity OnComplete Events list on the LogicController component.