Accessing Graph Variables

Jerm 4 months ago updated by Lazlo Bonin (Lead Developer) 4 months ago 3

I'm not understanding the Variables API.

How do I reference a particular macro Graph in my assets folder? I realize it says:

var graphReference = GraphReference.New(flowMachine);

But I can't define the variable flowMachine.

Like, this doesn't work:

public IGraphRoot dragAndDroppedMacro;

Bolt Version:
Unity Version:
Scripting Backend:
.NET Version (API Compatibility Level):

IGraphRoot is an interface. Therefore the editor doesn't know what type it should draw. You want FlowMachine instead of IGraphRoot to access the instance by component.

If you want to assign directly to a macro it would be FlowMacro instead of IGraphRoot, but that will be permanent, so be careful. Either one is acceptable as a IGraphRoot in GraphReference.New.

Once you have a machine instance, that you can check the type in the machine by doing 

If (myMachine.nest.macro == dragAndDropMacro){ }

Looks like the API needs an update. Because one cannot say 

var graphReference = GraphReference.New(flowMachine);

GraphReference.New requires at least 2 arguments now. Unless I missed something? I had to put something more like

var graphReference = GraphReference.New(flowMachine, TRUE);


Fixed in the doc as per the other thread.

That flowMachine example is just any component you fetched normally, so something like flowMachine = myGameObject.GetComponent<FlowMachine>().