# Cleaning Up State Machine Spaghetti

**URL:** <https://forums.unrealengine.com/t/cleaning-up-state-machine-spaghetti/300647>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine\
**Created:** [December 5, 2014, 5:58am UTC](https://forums.unrealengine.com/t/cleaning-up-state-machine-spaghetti/300647 "2014-12-05T05:58:51Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zooch](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Zooch](https://forums.unrealengine.com/u/Zooch)\
**Post date:** [December 5, 2014, 5:58am UTC](https://forums.unrealengine.com/t/cleaning-up-state-machine-spaghetti/300647/1 "2014-12-05T05:58:51Z")

</div>

Hi guys,

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:

 ![](https://d3kjluh73b9h9o.cloudfront.net/original/4X/8/a/a/8aad87a840028191195f32d46c2360d475d8c144.png)  
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.

---

<div class="post-metadata">

**Author:** ![RAVaught](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@RAVaught](https://forums.unrealengine.com/u/RAVaught)\
**Post date:** [December 6, 2014, 1:14am UTC](https://forums.unrealengine.com/t/cleaning-up-state-machine-spaghetti/300647/2 "2014-12-06T01:14:10Z")

</div>

The animation updates from 4.6 should handle the transitions for you. Look at the release notes for details.

---

<div class="post-metadata">

**Author:** ![Zooch](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Zooch](https://forums.unrealengine.com/u/Zooch)\
**Post date:** [December 6, 2014, 1:43am UTC](https://forums.unrealengine.com/t/cleaning-up-state-machine-spaghetti/300647/3 "2014-12-06T01:43:51Z")

</div>

Can you show me where in the release notes it discusses more efficient handling of complex state machines (or transitions)? I seem to be missing it - scrolled through the release notes twice and did some control+F keyword searches with very limited results.

---

<div class="post-metadata">

**Author:** ![Zooch](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Zooch](https://forums.unrealengine.com/u/Zooch)\
**Post date:** [December 8, 2014, 9:17pm UTC](https://forums.unrealengine.com/t/cleaning-up-state-machine-spaghetti/300647/4 "2014-12-08T21:17:51Z")

</div>

Pinging this again.

---

<div class="post-metadata">

**Author:** ![RhythmScript](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@RhythmScript](https://forums.unrealengine.com/u/RhythmScript)\
**Post date:** [December 8, 2014, 9:36pm UTC](https://forums.unrealengine.com/t/cleaning-up-state-machine-spaghetti/300647/5 "2014-12-08T21:36:54Z")

</div>

Just popping in to say I totally feel your pain.

For me, it isn’t even the NUMBER of states that does it, it’s managing the transitions between them. The inability to adjust the curvature of the state transition lines, and the fact that transition arrows just sort of hover next to them rather than being visibly connected, makes it nigh impossible to figure out which thing I need to click on to adjust any given transition.

 ![23368-statemachinespaghetti.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/3/5/a/35ae306bb64982748fa23cc7ba5a8f1254f872ac.png)

---

<div class="post-metadata">

**Author:** ![anon26705860](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anon26705860](https://forums.unrealengine.com/u/anon26705860)\
**Post date:** [December 8, 2014, 9:52pm UTC](https://forums.unrealengine.com/t/cleaning-up-state-machine-spaghetti/300647/6 "2014-12-08T21:52:36Z")

</div>

Upvoted and following as I’m curious about Epics workflow.

My only potential recommendation would be to use some additive montages for certain one off situations when there is a default blend and not a premade transition out animation such as Dodging, Dashing, etc.

If you override upper body torso, head, arms, etc with certain additive slots you might not need certain transitions.

---

<div class="post-metadata">

**Author:** ![Zooch](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Zooch](https://forums.unrealengine.com/u/Zooch)\
**Post date:** [December 8, 2014, 9:57pm UTC](https://forums.unrealengine.com/t/cleaning-up-state-machine-spaghetti/300647/7 "2014-12-08T21:57:18Z")

</div>

Yeah your image is much closer to what mine looks like now. Pretty similar to my Christmas lights situation:

 ![](https://d3kjluh73b9h9o.cloudfront.net/original/3X/2/9/29f7617880a727f09030a913b43dbd319b595460.jpeg)

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_2a254ae9](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_2a254ae9](https://forums.unrealengine.com/u/anonymous_user_2a254ae9)\
**Post date:** [December 9, 2014, 6:25pm UTC](https://forums.unrealengine.com/t/cleaning-up-state-machine-spaghetti/300647/8 "2014-12-09T18:25:31Z")

</div>

You could setup all those transitions inside the “Blend Graph” of the “Transition Rule” itself to clean it up a bit.

Edit: A picture =\>

 ![BlendGraph.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/3X/9/c/9c736efcd4abeea19e816f9fed49cb0b1df5f1be.jpeg)

---

<div class="post-metadata">

**Author:** ![anon26705860](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anon26705860](https://forums.unrealengine.com/u/anon26705860)\
**Post date:** [December 9, 2014, 8:40pm UTC](https://forums.unrealengine.com/t/cleaning-up-state-machine-spaghetti/300647/9 "2014-12-09T20:40:11Z")

</div>

Is that in master branch or something? Its not in promoted.  
EDIT: I missed changing the blend logic to custom.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_2a254ae9](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_2a254ae9](https://forums.unrealengine.com/u/anonymous_user_2a254ae9)\
**Post date:** [December 9, 2014, 8:41pm UTC](https://forums.unrealengine.com/t/cleaning-up-state-machine-spaghetti/300647/10 "2014-12-09T20:41:07Z")

</div>

It’s 4.6 binary and I guess the feature is not even new in 4.6  
Edit: I’m almost sure it was there even in 4.5.1

---

<div class="post-metadata">

**Author:** ![RhythmScript](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@RhythmScript](https://forums.unrealengine.com/u/RhythmScript)\
**Post date:** [December 9, 2014, 10:36pm UTC](https://forums.unrealengine.com/t/cleaning-up-state-machine-spaghetti/300647/11 "2014-12-09T22:36:24Z")

</div>

Nah, I actually have a weird workflow that uses a LOT of transition notifies.

Basically, what I do is I control a lot of the character movement itself with the anim graph. I take inputs, feed them to the anim graph, let the anim graph attempt to drive states accordingly, and then use Anim Notifies or Transition Notifies to return information to the character BP to do the actual movements. This lets me control the “player state” in a sane way (i.e. if I don’t want the player to be able to double jump from a dodge, reload from a dash, etc., I simply don’t allow those state changes to happen period), though obviously it complicates the state machine a little bit.

---

<div class="post-metadata">

**Author:** ![RhythmScript](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@RhythmScript](https://forums.unrealengine.com/u/RhythmScript)\
**Post date:** [December 9, 2014, 10:37pm UTC](https://forums.unrealengine.com/t/cleaning-up-state-machine-spaghetti/300647/12 "2014-12-09T22:37:37Z")

</div>

It’s always “been there”, but the thing is there’s no documentation on it and it’s really unclear how exactly it works. I’ve tried several times to figure it out and have been unable to; and as a result, I’ve got several transition states that I feel are pretty irrelevant but I’ve been unable to eliminate them since I can never seem to get the Blend Graph to show like yours is.

---

<div class="post-metadata">

**Author:** ![Zooch](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Zooch](https://forums.unrealengine.com/u/Zooch)\
**Post date:** [December 9, 2014, 11:35pm UTC](https://forums.unrealengine.com/t/cleaning-up-state-machine-spaghetti/300647/13 "2014-12-09T23:35:33Z")

</div>

I’m in the same boat with this. I knew about this existing and have poked around myself but never got logical results. There doesn’t seem to be any documentation on this that I can find.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_2a254ae9](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_2a254ae9](https://forums.unrealengine.com/u/anonymous_user_2a254ae9)\
**Post date:** [December 10, 2014, 7:40am UTC](https://forums.unrealengine.com/t/cleaning-up-state-machine-spaghetti/300647/14 "2014-12-10T07:40:02Z")

</div>

What didn’t work for you? I guess I may have not yet give the feature enough time to reveal it’s problems. But so far it looks to work pretty well, only thing I wish is if there would be a way to setup the overall blend time from within the blend graph based on the length of the transition animation used in the blend graph.

---

<div class="post-metadata">

**Author:** ![RAVaught](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@RAVaught](https://forums.unrealengine.com/u/RAVaught)\
**Post date:** [December 14, 2014, 6:41pm UTC](https://forums.unrealengine.com/t/cleaning-up-state-machine-spaghetti/300647/15 "2014-12-14T18:41:16Z")

</div>

Under the “Root Motion from Everything” heading. I was under the impression that the op was talking about animation transitions. The new should handle the animation transitions, which should in turn make the state machine a little less messy, I would think.

---

<div class="post-metadata">

**Author:** ![Zooch](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Zooch](https://forums.unrealengine.com/u/Zooch)\
**Post date:** [December 15, 2014, 5:36am UTC](https://forums.unrealengine.com/t/cleaning-up-state-machine-spaghetti/300647/16 "2014-12-15T05:36:27Z")

</div>

I’m not making a single player game, so I can’t really make use of Root Motion From Everything. I’m also not blending montages, just the animation sequences themselves. I could hypothetically turn all of those animations into a montage I guess…

---

<div class="post-metadata">

**Author:** ![Zooch](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Zooch](https://forums.unrealengine.com/u/Zooch)\
**Post date:** [December 15, 2014, 5:38am UTC](https://forums.unrealengine.com/t/cleaning-up-state-machine-spaghetti/300647/17 "2014-12-15T05:38:08Z")

</div>

I just needed to get out of my own way. I’m working on blending two animations now based on simple logic from the AnimGraph.

I do have two questions though - why would you use the Get Source State Pose and Get Destination State Pose nodes that automatically generate?

Also, If you have a custom blend graph that plays different animations based on simple logic, and this all happens inside the transition, does it play the resulting animation (from the custom blend graph) then move to the actual state animation? Or does it just determine which animation to play once it hits the node its transitioning to?

I’m hoping it’s the former, but that means you can actually play animations in the transitions as well as the states.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_2a254ae9](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_2a254ae9](https://forums.unrealengine.com/u/anonymous_user_2a254ae9)\
**Post date:** [December 15, 2014, 10:42am UTC](https://forums.unrealengine.com/t/cleaning-up-state-machine-spaghetti/300647/18 "2014-12-15T10:42:29Z")

</div>

Get Source State Pose and Destination Pose are there probably so that you can actually blend between the state animation and transition animation used in the blend graph. If you notice you have 3 different options in the Source/Destination Pose - you can ask for last/first frame pose, you can constantly play the source and destination animations (I guess until the transition is over) and you can also ask for specific number of poses where last is kept as frozen.  
I think this is meant for two different purposes, one if you have a transition animation which doesn’t need to blend because it starts on the same frame as the animation from which you are transitioning and you make sure that the animation you are transitioning from will play to the end where it has the same pose as the first frame of your transition animation (well, I guess ideally you remove one of the same frames… either last frame of the animation or first frame of the transition animation). The other option, using the source/destination poses is probably meant for transitions where the poses/frames between source animation, transition animation and destination animation can’t be matched with certainty and so you have to blend them with some kind of crossfade logic.

As for the second question, I’m not sure I understand the point. I mean what is the core difference between the two options you are asking if it happens one way or the other?

---

<div class="post-metadata">

**Author:** ![Zooch](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Zooch](https://forums.unrealengine.com/u/Zooch)\
**Post date:** [December 15, 2014, 3:55pm UTC](https://forums.unrealengine.com/t/cleaning-up-state-machine-spaghetti/300647/19 "2014-12-15T15:55:11Z")

</div>

An example will probably clear the air:

Let’s say you have an Idle animation, a WalkLeftStart\_LeftFoot animation, and a Walk blend space. Let’s assume you have the other 3 WalkStart directions for each the Left and Right feet, so 8 total WalkStart animations.

Can you, while using the custom blend graph, determine which of the 8 WalkStart animations should be playing **and then play that animation** , _ **then** _ go into the WalkBS? Or does it not function this way?

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_2a254ae9](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_2a254ae9](https://forums.unrealengine.com/u/anonymous_user_2a254ae9)\
**Post date:** [December 15, 2014, 4:32pm UTC](https://forums.unrealengine.com/t/cleaning-up-state-machine-spaghetti/300647/20 "2014-12-15T16:32:07Z")

</div>

So I have some mixed results. The following stuff from the screenshot works (I know it’s not exactly what you wanted):

 ![24115-customblend_working.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/0/c/4/0c4e48fc7faceb9a8758cc5ee8915267d23483e2.jpeg)

The next thing is probably what you want, but unfortunately it doesn’t work. Notice the “Note” on the blend result node.

 ![24117-customblend_notworking.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/1/1/c/11c7925c73abe3a0fb889ab79beb165dc6f04a93.jpeg)

It “feels” like it should work, but can’t figure out why it doesn’t. Hopefully it’s “just” a bug. If this would work, I think it would be quite handy for taming the spaghetti monsters.

[Next page](https://forums.unrealengine.com/t/cleaning-up-state-machine-spaghetti/300647.md?page=2)
