+1
Answered

Replicating Action delegate behaviour in Bolt

Real World 3 years ago updated 3 years ago 4

What I'm trying to do currently is rip out the spaghetti UI code from an existing Unity app and replace it with Bolt so we can easier visualise the flow of the menus and also to allow us to add new menus into the flow more easily.

One problem I'm looking at currently is this... I have a few places in my existing C# code where I call a function and pass in an "Action" delegate as a parameter. That function stores the delegate and calls it when it is done doing whatever that function does (it could be play an animation for x seconds for example). I'm not sure how to replicate this in Bolt. I was thinking I could use CustomEvent.Trigger but the problem I see with that is that if my event is used in multiple Flow Graphs then all those graphs will receive the event and continue rather than the one in the current flow. I kind of want a CustomEvent with an input node that doesn't watch for the event unless it is currently active.

Have you got any suggestions?

Bolt Version:
Unity Version:
Platform(s):
Scripting Backend:
.NET Version (API Compatibility Level):
GOOD, I'M SATISFIED
Satisfaction mark by Real World 3 years ago
Answered

Hi Real World,

Delegates are a really complex beast to replicated in visual scripting, so I'll focus on the workaround for now.

if my event is used in multiple Flow Graphs then all those graphs will receive the event and continue rather than the one in the current flow [...] I kind of want a CustomEvent with an input node that doesn't watch for the event unless it is currently active.

The custom events should only trigger:

  • On the game object that was registered as the listener (first port)
  • If the flow graph with the event is active (for example, it won't trigger in inactive states)

If these conditions are not "narrow" enough for your use case, you can consider passing a more specific argument in your custom event (for example a string called "filter"), and branch/compare on that string in the receivers.

For example:



So if I have a Super Unit and inside that super unit is a custom event (amongst many other things). The Super Unity has an input and output control. It appears that if I duplicate that super unit and use it in two places within the same parent flow graph that the event is called on both super units even though the flow only went into one of them. Is that right? It seems to me like everything in an instance of a super unit should be disabled if it hasn't had the flow enter that instance. I hope I'm making myself clear. The workaround you suggest works but clutters up a graph no end and is unworkable in a flow graph with a lot of custom events.

+1

Super units have no notion of "receiving the flow". Some super units have no flow input at all, while others can have multiple. If you want to add this limitation, you can do another check before going forward with the event, i.e. checking if the flow from a specific port has been entered before triggering the rest of your graph.

How do you do that?