Call Event at Graph Level

JasonJonesLASM 4 years ago updated by Lazlo Bonin (Lead Developer) 4 years ago 8

This is something I ran into because of recursion issues. I attempted a fake, but succeed at a very hacky while loop that is like an IEnumerator yield return. It's a bad hack though. As I have to embed each graph to make it an instance, while constantly checking a variable is true with Update, to allow it to enter a conditional loop. 

I'd assume all updates must constantly be running in each one, while the game object is enabled. That's a lot of individual Update checks constantly happening everywhere just to see if it can loop.

I'd either suggest more Control units for conditions and time based loops, or my other suggestion is Graph level event calls. Call the event inside the while loop graph I make, when you get to it, and call another event to call the original to re-enter every frame. Eventually the condition becomes, not true, and the event is no longer called and it passes. To an exit node. Nothing being called every frame other than when the loop happens. 

I'm sure there is more you could do, but that's my first major run in with this limitation. Does this make sense? Not at my computer, but I can provide photos of it if necessary.

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

Okay, well I made photos anyways. 

How it is done right now:

How it should work perhaps?


It's unlikely that I ever add different scopes for events (like there are for variables for example), due to the added configuration complexity. Your first workaround is a good way of handling that situation. But instead of checking at update, you could simply check in your flow input, right before setting your boolean variable.

Understandable, I'll check that out. This is essentially replacing Coroutines for me. That's my attempt anyways. Doesn't Update fire as long as the containing Flow machine is enabled? In order to update constantly when reached, you'd need an update event. So have 10 in a sequence, wouldn't all 10 be updating? Even if you are 20 units passed the last one fired.

Maybe I'm not understanding what I originally read in the manual. 

I don't understand your question, sorry :/

Yes, update fires as long as the state machine is enabled. But if you have no update event, it does nothing.

No problem. This is only intended as an equivalent to C# StartCoroutine with a while loop yield return null. 

If I don't have an update, how can I fire something over multiple frames until its condition isn't true, then continue the exit flow. It will only fire once then.

I'll give you a concrete example. You have 10 enemies. Each enemy can attack. But this attack has 3 states. Say they first is a pump up rage animation and gains health, followed by a ground pound, then dash. Each needed to wait for the previous to finish. Something needs to check that it hasn't finished so it can loop it's gaining of health, ect over many frames. 

In this case, even if the enemy is unaware of you, and idle, all updates still fire. If I don't have one, it'll only check and fire once, or never. This make any more sense?


Yes it does! For your particular example, I would highly recommend using a state machine with your 3 states. Remember you can also nest a state machine inside a flow graph with a State Unit. 

In general, there is no way to simulate a coroutine without an update -- this is actually what coroutines do behind the scenes!

Tried it out, works perfect! Didn't realize updates don't fire if not in the state on state units. Plus it seems much easier to accomplish.This does exactly the same thing as I was trying to do in a very hacky way. Thanks for the tips.

All events in states only trigger when the state is active :) That's what makes state machines so useful!