Why do we only return after some state transitions?

In the 3rd Person Character controller with state machines, I noticed that we don’t always have a return statement after calling a SwitchState to another state. I added one in for a few instances to see if that made a difference, but if there was a change, it wasn’t anything I noticed. Does it matter if we do or don’t return?

A void method ends automatically in the absence of a return statement.

Where it becomes important is that you really don’t want more Tick() code running after switching states, as while the new State() will be created and the old state Exited, if there is more code that’s allowed to run after SwitchState() in the Tick() (or a method that Tick() called!) then the rest of Tick will run AFTER all of that has happened, and could lead to unexpected results. The return statements never HURT, but it’s important to think about flow control at all times to avoid running code at inopportune times.


Privacy & Terms