UnitAI quite often uses SetNextSWhen setting the next FSM state when processing orders.
This can lead to weird issues when we are already in that state, we generally want to leave and re-enter if we are setting the same state (for whatever reason), since we won't leave-re-enter but just silently change our orderso that cleanup gets properly handled.
This isn't so much of a problem in FSM code since we know what state we are in.
If unitAI really doesn't want to leave-reenter when processing an order, it should validate explicitly that it is safe to do so.
---
I've run into this issue in D13, with Gathering. in Gathering.Approaching.enter, I start a timer if we can gather from our current resource, but I call "Order.Gather" (through PerformGather) if the resource is full - and don't start the timer, because who knows what may happen.
However since Order.Gather uses setNextState, we don't re-enter. Thus the timer never gets set, and things get broken.
I believe the correct fix is here is to re-enter, not try to have complete behaviour in "enter" every time as that leads to way more kludgesChange so the default case if with re-entry.