Is there a way to instantiate an object at runtime with an Animator Controller at the same animation time as another?

Hey!

So I have an object in the scene with an Animator Controller playing an idle animation.

While the game is running I’m instantiating a new object with the same animator controller, but I need the animations to be playing at the same time. It’s almost as if Unity is creating a clone Animator Controller because they’re both running the Idle animation at different times, starting from when they were created.

The only solution I found so far is triggering the animation to start again without any blending when I instantiate the new object but that makes the position of the original snap.

I tried getting the runtimeAnimatorController of the original object and assigning that to the new one when it’s instantiated but that still had the animations playing at different times.

Anyone know of a good solution to this? Is there a way to set the animation position for the new object?

Thanks!

You will need to update the time for each animation state in the animation. Something LIKE this (I haven’t tested it):

// Reference to the animation in question, just made it public here, but would depend on your code
public Animation animCurrent;
public Animation animNew;
void Start() {
    foreach (AnimationState stateCurrent in animCurrent) {
        foreach (AnimationState stateNew in animNew) {
            if (stateNew.name == stateCurrent.name)
                stateNew.speed = stateCurrent.speed;
        }
    }
}

There’s probably a better way to do this without having to do the second for loop, like animNew[stateCurrent.name].speed = stateCurrent.speed; but I’m not sure.