How to properly retarget animations?

I have a web app that is like mount and blade. I have some humanoid avatars running around a world map.

The issue I’m facing is animation retargeting. If I load the page and the characters were mid walking, then the animation retargets properly. Presumably because the target avatar was in a rest pose matching the rest pose of the animation avatar.

However, if the character was standing idle, and then begins walking, the animation gets badly retargeted.

I’ve tried to reset the avatar, pre warm the animations and all of that, but nothing seems to give a clear consistent result.

Any advice on the proper way to setup animations so they are retargeted properly? Best practices? Correct methods to use to reset the skinned mesh renderer to its rest pose and retarget or something?

Thanks for the help

cc @Evgeni_Popov (please be patient he is on vacation)

Hello? Any insights you could share with me? How to properly go about reseting the avatar so the retarget works properly… Thank you

It sounds like the character isn’t returning to its original pose before the walk animation starts. I’d make sure both characters use the same T-pose or A-pose, retarget the animations once when the character loads, and then just switch between idle and walk instead of retargeting every time. I’d also check that no other animation or script is affecting the bones during the transition. If you mention which engine you’re using, it’ll be easier for others to suggest a fix.

cc @Evgeni_Popov

Hi! What you’re describing is almost certainly retargeting being run while an animation is already playing on the avatar.

Under the hood, AnimatorAvatar.retargetAnimationGroup returns each skeleton to its rest pose to compute the bone offsets it needs (returnToRest() internally, plus the root/ground fixups). That’s why it looks fine when you load with the character mid-walk (the skeleton is basically at rest at that moment) but goes wrong when you retarget at the idle→walk transition — the active idle pose gets disturbed.

Two recommendations:

1. Make sure you’re on 9.7.0 or newer. This was a real bug — retargeting clobbered any animation already playing on the avatar (see After Anim Retarget Stopping Current Animation Jumps to Rest Pose, fixed in PR #18450). If you’re on an older build, please upgrade first and re-test.

2. Retarget once, up front — not on every state switch. Retargeting is a one-time setup step that produces a reusable, already-retargeted AnimationGroup. Do it at load time for every clip (idle, walk, run, …), cache the resulting groups, and then just start() / blend between those cached groups when the character changes state. You should never call retargetAnimationGroup at the moment you begin walking — that’s what makes the result depend on the current pose. This also matches @mamta25’s suggestion above.

Docs and background:

To help pin it down, could you share: (a) your Babylon.js version, (b) whether you’re using AnimatorAvatar or a custom retargeting approach, and ideally (c) a small Playground repro? With those I can tell you exactly where it’s going wrong.

Thanks a ton @Evgeni_Popov !!!