Reliable Means of detecting animation state % complete

I’m trying to find a means of reliably (and cleanly) determining when an animation state has played through to the next transition. I see a few approaches atm, none of which are well designed or reliable.

  1. Create a curve, use it as a pseudo-bool that goes from < 1 to >= 1, detect this in code and treat that as ‘done’.

Pro: Can “tweak” when you’d expect to be done for each animation.
Con: A hack, this is creating superflous state and bleeding that information to the client, to tell me something I should already know.

  1. Poll for a transition state or state change.

Pro: Fairly simple to do.
Con: Lots - “polling” for state information in a game loop? lack of encapsulation - i.e. “knowing” about a state by name that i’m in.

  1. Compare current play progress vs “total length” of that state.

This is what i’m attempting now, it seems to work but i’m not fond of having to ‘know’ about the layer/animation names here. Has anyone found a cleaner means of determining the percentage of a state, kind of like when you watch the Animator window and you see the blue progress bar filling up - i’d like to know THAT value so I’m able to ignore (for some cases) layers, clips, etc… just want to know the general % done for a given state.

		// based on animation state info, determine if we are done the 'vault' animation
		AnimatorStateInfo stateInfo = animator.GetCurrentAnimatorStateInfo( 0 );
		float normalizedTime = stateInfo.normalizedTime - Mathf.Floor( stateInfo.normalizedTime );
		if( stateInfo.IsName( "MainLayer.Vault" )  normalizedTime >= stateInfo.length )
		{
			End( Inputs.Type.Default );
		}

I’m thinking there must be a more reliable way of knowing when a state has played it’s course and is ready for a transition.

I assume youre looking for something more complex than…

animation[“anim”].time/animation[“anim”].length

but im going to post it anyway since its a percentage of animation played :stuck_out_tongue:

Well, I’m thinking we want the same kind of calculation but at the animation state level so as to account for blending, speed, etc… You’d think normalized time would do this, perhaps it does and I am missing something here.

Hi! This is exactly what I want. Do you find the more reliable way? Thanks!