Retrieving State Machine current state info from Linked AnimLayer

We found ourselves wanting to use motion warping on non-montages for our project, and when I looked into it, it seemed that most of the motion warping code operated on AnimSequences, but the main issue was that the code in UMotionWarpingCharacterAdapter::WarpLocalRootMotionOnCharacter() would only execute if the Character had it’s RootMotionAnimMontageInstance set.

We found a way to augment this by overriding the WarpLocalRootMotionDelegate called at the end of this function, and in ours it also tries to fill out the WarpingContext from an Animation Sequence (if it’s not already filled out from a montage). I did this by making a child class of URootMotionModifier_SkewWarp that has another Name field in it for the name of the StateMachine the Animation Sequence with a Motion Warping Notify is in. Then in our delegate, we search the Character’s Mesh’s AnimInstance for the state machine of the name in our SkewWarp subclass, and from there we get the current state elapsed time, previous time by subtracting delta seconds from that, and Weight from the state machine’s current state’s weight, and use those to fill out the Warping Context.

This seems to work reasonably well, but we are also linking AnimLayers on our Characters, and some of them have state machines in them that have animations that we want to use Motion Warping for as well. I can retrieve a reference to the Linked Layer Class Instance with the UAnimInstance::GetLinkedAnimLayerInstanceByClass(), and find the state machine on there, but it’s CurrentState is always -1, and thus I cannot retrieve timing or weight information.

I can see in the Rewind Debugger that the Linked AnimLayer’s AnimGraph is returning the State Machine in question, and the State Result shows the correct name of the state that is active, but the reference from GetLinkedAnimLayerInstanceByClass() shows me CurrentState as -1.

Is there a different way I can retrieve that information?

I’m sure we can’t be the first project that wanted to have Motion Warping on Animation Sequences, so if there are other methods that have been successful, would be interested to hear about them, or if there are any obvious flaws in our approach.

Thanks,

- Joe

Hi Joe, what API are you using to get back the state from the state machine name? You should be able to do this from the top-level anim instance, you shouldn’t actually need to go via the linked instance. So, it may be that you’re running into a bug with whatever API you’re using.

In terms of the route you’re going down to allow warping of anim sequences within the graph, what you’re doing sounds broadly in line with the approach we would go with if we added support for motion warping outside of montages. However, you didn’t mention how you’re actually getting the root motion from the animation within the state - are you manually sampling the animation that lives within the state?