0
Answered

Accessing Graph Variables

Jerm 1 year ago updated by Fyodor Krasniy 2 months ago 4

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:
1.4.5
Unity Version:
2018.2.19f1
Platform(s):
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);

Answered

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>().

Heya sorry for bringing this up, Im just a bit confused about how accessing embedded graphs actually works, this thread was as close that I could find to it. 

Lets say Im trying to set a variable inside a nested graph..

var flowMachine = this.GetComponent(); //as far as I understand this is the path to the graph 

var graphReference = GraphReference.New(flowMachine, new IGraphParentElement[] { ??? } () }, true);

What goes into the IGraphParentElement? 
I couldnt quite figure that out, its not a string its not another flow machine.. Still wrapping my head around interfaces n things. 

Thank you for anyone who sees this!