It seems that the previous State's OnHeartbeat and (maybe) OnLeave functions sometimes continue running a little, even while the next State's OnStart and (maybe) OnHeartbeat functions are running! This seems to happen because of your use of task.defer. This is not good as, most would rightfully assume that the OnStart function would only run, after the last state has left!
It seems that the previous
State'sOnHeartbeatand (maybe)OnLeavefunctions sometimes continue running a little, even while the nextState'sOnStartand (maybe)OnHeartbeatfunctions are running! This seems to happen because of your use oftask.defer. This is not good as, most would rightfully assume that theOnStartfunction would only run, after the last state has left!