Cleaning Up State Machine Spaghetti
I have a state machine with roughly 75 states that controls my entire character locomotion system. I have so many because I have start/stop animations for each direction and each movement type, as well as jump/fall cycles for everything. I also have transition animations between movement types.
It all looks pretty as hell in-game when it works, but my state machine is a huge mess. Here's an old picture of my state machine graph, with ~30 of my 75 states:
Now imagine double the states and quadruple the little arrow lines. If I have to change one "thing" that affects 16 states, it takes me 45 minutes to just search for all the transition rules and make the change.
Do you guys have any tips for cleaning up this mess? I, the creator of the state machine, can hardly work with it without getting confused and changing the wrong rule. There's no possible way I could hand this to someone else to work on. Keep in mind the picture I'm showing you is about 25% of the current state machine size.
That would be so mean.
asked Dec 05 '14 at 05:58 AM in Using UE4
I'm just starting out, but one of the things I'm doing now in this early phase to mitigate complexity is making sure that logical animation state is controlled by a single enum in code. I then use a single conduit to transition to any state based on that one enum. The anim state machine will transition out back to the conduit if that enum changes into one that is not meant for that state.
This is a very early example...
In short, I made sure that all gameplay logic existed outside of this AnimGraph and only in code.
Sticking with this single-enum starburst pattern allows me to add states with no dependency on current state since that complexity is handled by code, which is way easier to manage than boxes and lines. If code is not an option, you may still benefit from this type of pattern by managing that enum in a separate blueprint that decouples gameplay logic from animation logic.
So, I also did a research before getting into that spaghetti mess. I would add to conduits and selects, also nested State Machines. I found this example, that shows how a complicated state machine can be split into multiple: https://www.youtube.com/watch?v=MyqZIRH5UP8
answered Mar 20 '17 at 10:31 PM
The animation updates from 4.6 should handle the transitions for you. Look at the release notes for details.
answered Dec 06 '14 at 01:14 AM
Follow this question
Once you sign in you will be able to subscribe for any updates here