0
Fixed

Coroutine flow doesn't stop while FlowMachine is disabled [1.4.0 beta 3]

cooloon 2 years ago updated by Lazlo Bonin (Lead Developer) 2 years ago 7

If you create an flow graph looks like below and run it, then disabling the FlowMachine doesn't stop the running coroutine.

This happens because disabling FlowMachine doesn't make any effect on the coroutineRunner it runs on, but we expect the graph to be stopped, don't we?

And a option here may be a behavior of resuming. When enabling the FlowMachine again, do we lost the stopped coroutine?

Bolt Version:
Unity Version:
Platform(s):
Scripting Backend:
.NET Version (API Compatibility Level):
GOOD, I'M SATISFIED
Satisfaction mark by cooloon 2 years ago
Not a Bug

Hi cooloon!

Since 1.4, Bolt is smarter at inferring which object should be running the coroutine, and in this case it would be the flow machine component at the root of your graph chain.

What you are seeing I believe is not a bug, but just how Unity is designed: disabling a component does not stop its coroutines (deactivating the game object does, though!). It's kind of a quirk and I can't find the documentation for it anywhere, but this Unity Answers post addresses it: https://answers.unity.com/questions/34169/does-deactivating-a-gameobject-automatically-stop.html

If you want to stop coroutines when disabling, I suggest you add an On Disable event in your graph, and link it to a Stop All Coroutines unit.

Lazlo, thanks for your quick repry and kind explanation!

I've misunderstood the cause of this and how Unity works. You're right, this is not a bug and the best way to stop coroutine is using OnDisable event.

Note for somebody who read later:

If you want to stop coroutine flow, you must use StopAllCoroutines unit of FlowMachine type (or StateMachine type if your coroutine flow is running on StateMachine). StopAllCoroutines unit of MonoBehaviour type or any other types doesn't work.

+2

Note for somebody who read later again: 

For v.1.4.0f10, coroutine will be stopped when its machine is disabled. See this topic for details: https://support.ludiq.io/communities/5/topics/2298-coroutine-transitions-lead-to-multiple-active-states

+1
Fixed in Next Version

Ah yes, indeed!