Assigning a Flow Macro to a GameObject and Calling a Custom Event Without An Object

RoxasCoolidge 2 years ago updated 2 years ago 4

Hi, I've recently tried doing two things in Bolt (replicating from a C# tutorial I found), and I'm having some issues

The first I've seen asked before, but had no answer. And it is basically this:
I have a Macro that creates a new game object and adds a "FlowMachine" component, however I can't seem to be able to actually assign a Macro to said FlowMachine. Is that possible? How?

The second might be impossible, but I was curious anyway:
Can I trigger a custom event from a Macro never assigned to an object?
Basically, I have two Macros, A and B. A is assigned to my character and at Start it has a "Trigger Custom Event" found in B. However B is not assigned to any GameObject. Is there any possibility of still triggering this event, or is that impossible? I think I've seen something similar done with actual C# scripts, so I was curious if this is the case here as well.


Bolt Version:
Unity Version:
Scripting Backend:
.NET Version (API Compatibility Level):
Satisfaction mark by RoxasCoolidge 2 years ago

Hi Roxas! Good questions.

So first off, assigning a macro from script. It's undocumented in the API and not technically officially supported, but you should be able to do it like that (off the top of my head):

var machine = AddComponent<FlowMachine>();

Now, triggering an event that's not registered on the event bus at runtime is also technically undocumented and unsupported, but you could do it with:

var reference = GraphReference.New(macro);
reference.TriggerEventHandler(hook => hook.name == EventHooks.Custom, new CustomEventArgs("eventName"), parent => true, true);

Thank you! This worked well. So far that should suit my needs.

Just to make sure though, the first one can't be done from a Graph within Bolt, using only nodes? I have to use a script outside of it?

They are of course intended for scripts to generate functionality for the graphs, nodes, and such, but that won't stop you from trying. I've done it before. Just make sure before hand, you are certain, that you constantly back up, as a bad mistake can wipe a graph very easily working with internal functionality inside a graph.

The first very easily and safely, can be done in a graph. The second uses lambdas, which will at least require that to be placed in a script. Perhaps next alpha it's possible with delegates and such. 

Theoretically your only limited by the C# constructs that are left to be implemented, and the lack of attributes and csharp generation for true types, where reflection bolt side needs to find a script to have it work.

Not normally recommended, but experimentation is half the fun. Just as long as your prepared. Much easier to edit a script that can't be broken, then trying to fix a broken graph from using internals wrong.

I suppose I should be less scared of experimenting, I'm even using a dummy project in case everything goes awfully wrong =P

The second one I can keep on scripts, but I'll try it whenever the next alpha comes out and I have some free time.

Either way, thank you both so much for the help! Bolt has easily been some of the most fun I've had in Unity so far.