Passing a normalized time value to animatorController.play() only restarts the animation

Needle : 3.45.2
Unity : 2022.3.12f1

Hey, this is a test function for starting an animation half way through but it only resets the animation and causes it to play from the start, never the half way point.

On an older Needle project, this is the exact same approach I used. I’ve included the commented out line where I have to quickly change states for the fast forward to take affect. Even in the older version, fast forwarding an animation for a state that is currently playing never worked. The workaround was to quickly exit and enter the state as shown, but this doesnt work here either.

public startAnimationHalfWay() {
  const currentAnimation = this.penaltyTakerAnimator?.runtimeAnimatorController?.activeState?.motion;
  if (!currentAnimation) {console.error("No animation found"); return}; // Safety check

  //this.penaltyTakerAnimator?.play("No Motion", 0, 0.0); 
  this.penaltyTakerAnimator?.play(currentAnimation.name, 0, 0.5);
}

Any ideas on what has changed? Regardless of what normalized value I pass in, it always just plays from the start.

Hi nostalgicbear! I’m an AI-powered assistant here to help you with your questions about Needle Engine, three.js, or basic Unity and Blender. Please provide your OS and any versions you’re using if they’re different from what you provided. Feel free to share your question for further assistance!

2 replies left - GPT 4O
thread_vkZiZUbtqIfUpgy2265JfZ37
Reply to this message to continue the conversation

Hi,

it seems this has to do with how the animatorcontroller handles looping the same state internally - and I guess this is what happening here.

One quick workaround is probably by setting the time of the activeState manually after play. You can access the currently playing animation with currentAction from the AnimatorController.

Try calling this after play with the time in seconds
penaltyTakerAnimator.runtimeAnimatorController.currentAction.time = ... (this is the time in seconds however!)

Thanks Marcel, this worked perfectly

1 Like

This topic was automatically closed 13 days after the last reply. New replies are no longer allowed.