How to change specific animation's speed at runtime using AnimComponent?

As the title says, how can I change specific animation’s speed at runtime using AnimComponent? AnimComponentLayer does not have a speed attribute.

I found it, but there is a small adjustment you need to do it every time.

var entity = pc.app.root.findByName("entity_id")

This function returns the clip object when the current animation is run. It returns null if the current animation is something other than ‘run’. To handle this, I created an ‘Anim Event’. At the beginning of the ‘run’ animation, I check a certain state. If it is true, I update the clip’s speed.

var clip = entity.anim.layers[0]._controller._animEvaluator.findClip("run");
clip.speed = 2;

Nice find, thanks for sharing!

Curious if there is an official way of doing that, without having to use private properties. @Elliott @yaustar

1 Like

No official API. Will open a ticket on being able to change a layer’s and state speed.

At the moment, you can only change the speed at the Anim Component level