Closed Chocolaic closed 6 months ago
Feels a bit like this is more complexity than needed imo! Coroutines are a mess
Hi @Chocolaic, Thanks for your PR! Having coroutine-based transitions is very interesting and a feature I hadn't considered before.
One of the main architectural choices of transitions in UnityHFSM is that they do not have any side-effects, i.e. they do not "do" anything, but only tell the state machine when a state change is allowed to happen. "Doing" things and elegantly writing the code for sequential behaviour is one of the main advantages of using coroutines. Timing without performing actions is already supported by UnityHFSM. For instance, you could implement your example using two transitions: one transition for when the key is pressed, and one for when the delay elapses (using a TransitionAfter
).
As UnityHFSM can essentially already do what you are asking for and using coroutines makes the code more complex, I will not be merging this pull request. I do, however, appreciate the effort.
Hello, I'm trying a way to handle complex logic in time sequence
An example shows that the player enters the aiming mode after holding down the right mouse button for one second. use 'yield return true;' to transition to another state and false to restart transition.
However, it not a coroutine in unity thus 'yield return new WaitForSeconds()' may not work. This requires manual implementation of the method in the coroutine. XD (I didn't find a method like OnExit in Transition to stop coroutine properly or ignored by me)