x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Cleaning Up State Machine Spaghetti

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:

alt text

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.

Product Version: Not Selected
Tags:
more ▼

asked Dec 05 '14 at 05:58 AM in Using UE4

avatar image

Zooch
176 15 18 32

avatar image Zooch Dec 08 '14 at 09:17 PM

Pinging this again.

avatar image RhythmScript Dec 08 '14 at 09:36 PM

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.

alt text

avatar image dzeligman Dec 08 '14 at 09:52 PM

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.

avatar image RhythmScript Dec 09 '14 at 10:36 PM

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.

avatar image Zooch Dec 08 '14 at 09:57 PM

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

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

4 answers: sort voted first

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

Edit: A picture => alt text

blendgraph.jpg (324.0 kB)
more ▼

answered Dec 09 '14 at 06:25 PM

avatar image

doC
107 6 13 20

avatar image dzeligman Dec 09 '14 at 08:40 PM

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

avatar image doC Dec 09 '14 at 08:41 PM

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

avatar image RhythmScript Dec 09 '14 at 10:37 PM

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.

avatar image Zooch Dec 09 '14 at 11:35 PM

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.

avatar image doC Dec 10 '14 at 07:40 AM

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.

avatar image Zooch Dec 15 '14 at 05:38 AM

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.

avatar image doC Dec 15 '14 at 10:42 AM

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?

avatar image Zooch Dec 15 '14 at 03:55 PM

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?

avatar image doC Dec 15 '14 at 04:32 PM

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

The next thing is probably what you want, but unfortunately it doesn't work. Notice the "Note" on the blend result node. alt text

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.

avatar image Zooch Dec 15 '14 at 05:13 PM

The blend based on int value was my issue as well. That's what I originally tried to do and failed with, then I recently tried again using the bool value in your first image and it seemed to work fine, so I figured I just screwed it up the first time when using blend by int.

Maybe it's actually bugged though. I wonder if I could use blend by bool like 8 times in a row :D

avatar image doC Dec 15 '14 at 05:25 PM

Sir, you want to take the responsibility to post that bug or should I? :) At least I hope it's a bug, worst case we learn how to do it properly.

As for 8 bools, let us know if you try :)

avatar image Zooch Dec 15 '14 at 06:49 PM

I'll post it. I'm pretty slammed at work through Christmas, but I hope to try the 8-bool approach soon :)

avatar image Zooch Dec 15 '14 at 07:01 PM
avatar image doC Dec 15 '14 at 07:09 PM

Thanks for the link, really hope it's only a bug, or maybe a not finished feature and soon it will work. Even now the animation system in UE is fantastic, if this feature would be fixed, it would be getting quite close to being perfect :)

avatar image SND R Keene Jun 17 '15 at 10:29 PM

Select is not supported in animations like that. You HAVE TO use a blend.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

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... starburst pattern

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.

capture.png (58.4 kB)
more ▼

answered May 12 '16 at 07:09 PM

avatar image

Kain Shin
96 1 6 6

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

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

more ▼

answered Dec 06 '14 at 01:14 AM

avatar image

RAVaught
669 37 26 66

avatar image Zooch Dec 06 '14 at 01:43 AM

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.

avatar image RAVaught Dec 14 '14 at 06:41 PM

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.

avatar image Zooch Dec 15 '14 at 05:36 AM

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...

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

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

more ▼

answered Mar 20 '17 at 10:31 PM

avatar image

Flash7
739 8 13 19

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question