Playing an animation from start once active?

Is there a way to play an animation sequence from it’s first frame and then set it to loop ?

I have a ledge climbing system where I blend from an idle animation to a moving animation. My problem is that the animation blend randomly in the timeline of the animation. I need to restart the animation from 0 once it’s branch is active (when the blending from the idle to the moving animation start). Otherwise I get some nasty transitions because some poses in the animation are too far from the idle pose.

I was able to do it in UDK via a custom animation node, with something like this (unrealscript code) :

//when this node become active, we restart the animation from 0
//usefull for looping animation like ledge movements
event OnBecomeRelevant() 
{
	SetPosition(0.0f, false);
}

Is this possible in UE4 ? Do I need a custom node too for that ?

I tried to use a State machine with a entry and then an idle loop but it didn’t work. I could do a looping of a montage, but it’s really not an elegant and optimized solution in my opinion. :'|

I’ve also been banging my head against UE4’s animation system for some time now coming from UDK. The only proper way I’ve found to solve this is to

  • Create a Montage, and add both your single animation and looping animation to it.
  • Use this post as reference to set the looping animation correctly.
  • Create an AnimBlueprint with a single default node plugged into the final pose
  • Play the montage from code via SkeletalMeshComponent->GetAnimInstance()->Montage_Play(YourMontage);
  • You can also set the currently playing montage position via SkeletalMeshComponent->GetAnimInstance()->Montage_SetPosition(YourMontage, pos)

Really, the only way you have any control over animations from C++ is to use montages.

I’d recommend using states with climb and idle and make sure you have blending time for transition to be 0.f so not to be not confused with blending vs playing from start.

If you look at the state, it should show, where the animation starts when it gets activated. Inside of state, we reinitialize it whenever gets activated, so it should work.

Thanks,

–Lina,

With the help of Lina I was able to get it working via a State machine. :slight_smile:
Here is the setup :

When the player is climbing a ledge I will enter the state which for the moment looks like this :

  • “Idle” is simply the idle animation when not moving along a ledge.
  • “LedgeLeftStart” is my moving animation to the left, but NOT looping.
  • “LedgeLeftLoop” is my moving animation to the left (the same one) but looping this time.

The condition to go from idle to LedgeLeftStart is just two boolean that I setup to know is the player is moving, and if he is moving to the left. If one of them is false, I got bakc to idle (hence the back and forth on the transitions o nthe graph).

The condition from LedgeLeftStart to LedgeLeftLoop is true if the animation from LedgeLeftStart has finished (and if the player is still moving), this means the first loop has been made and I can enter the loop state. The blending time between those two states is set to 0 as Lina mentioned. This way on the screen you have the feeling it’s the same animation that is looping. This is the most important part of the graph of course.

The result looks like this : Vine