# Animation weighting issues

**URL:** <https://forum.babylonjs.com/t/animation-weighting-issues/21363>\
**Category:** Questions\
**Created:** [June 3, 2021, 12:56am UTC](https://forum.babylonjs.com/t/animation-weighting-issues/21363 "2021-06-03T00:56:03Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![Antidamage](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/antidamage/32/19857_2.png) [@Antidamage](https://forum.babylonjs.com/u/Antidamage)\
**Post date:** [June 3, 2021, 12:56am UTC](https://forum.babylonjs.com/t/animation-weighting-issues/21363/1 "2021-06-03T00:56:04Z")

</div>

I’m having difficulty understanding how skeletal animations fit into babylon. I know that I can tell the scene to play a skeletal animation.

What I’d like to do is to take animations from two identical skeletons, apply one as additive and adjust the weighting.

From the documentation it looks like that weighting is an attribute of an AnimationGroup, and from the limited examples in the documentation it looks like animation groups can only contain simple procedural animations.

Is there a way to get a skeletal animation as an object and add it to an animation group?

I may be able to frame this question better as well. Let me start over.

I have a mesh with additional morph targets and an animation track.

The animation track goes like this:

Frame 0: T-pose  
Frame 1-60: idle loop  
Frame 61: enlarged skeleton

Then there’s an accompanying morph target to go with the enlarged skeleton. Frame 61 stretches the bones, and the morph target increases the bulk of the model.

When I import the mesh it begins playing the entire file automatically. If I tell the scene to play frames 1-60 it doesn’t work and the mesh import task stops executing, with no error output.

Additionally, when I inspect the mesh object, I can’t find the animations it’s playing anywhere, even in the bones. The mesh HAS a skeleton, but it seems like the skeleton is also imported separately to the scene. Are both skeletons the same reference?

I don’t think I can do any additive blending to apply the enlarged skeleton without a reference to the animation. It’s very frustrating.

Additional issues:

I’ve found the animationgroup for the mesh. I can stop the animation, but if I start it again I only have control over the rate, not the from/to. It just ignores from/to.

```
        importedData.loadedAnimationGroups[0].stop();
        importedData.loadedAnimationGroups[0].start(true, 3.0, 1, 60, false);

```

Okay! On the first loop it plays from To and finishes at From, but after that it just plays from start to end. That’s a bit useless.

More insight: I see in the AnimationGroup that each bone animation track is a child (a track for position, rotation, scale, etc.) That’s good, at least I know where they are now.

- Setting \_from and \_to does nothing.
- Using start() does not update\_from or \_to. Playing the animation does not use \_from or \_to.
- And finally, I can’t even handle it in an observer because the docs do not specify what [target] is in Scene.BeginAnimation(). It’s not a mesh, skeleton or animationgroup because none of those things cause the animation to start playing if it’s stopped.

Finally, the issue appears to be (thanks Scene debug layer!) that GLTF animations in Babylon don’t respect the To and From times, whether they’re entered in frames or seconds.

Part of why I’m hung up on this is Cinema4D only exports a single animation group and I don’t want to learn to rig and animate in Blender.

What I may try to do is clone my file, do the animations individually and then import everything and just use the animation groups on the single visible mesh.

My biggest concern however is this: if GLTF doesn’t support any animation controls aside from start and stop with no arguments, how is additive blending supposed to work?

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [June 3, 2021, 3:57pm UTC](https://forum.babylonjs.com/t/animation-weighting-issues/21363/2 "2021-06-03T15:57:43Z")

</div>

All right!🙂

To make sure we can help you as fast as possible, I would highly recommend to create a simple repro in the Playground. This will be far easier for everyone to provide guidance or even solution 🙂

---

<div class="post-metadata">

**Author:** ![Antidamage](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/antidamage/32/19857_2.png) [@Antidamage](https://forum.babylonjs.com/u/Antidamage)\
**Post date:** [June 15, 2021, 4:43am UTC](https://forum.babylonjs.com/t/animation-weighting-issues/21363/3 "2021-06-15T04:43:00Z")

</div>

I’ve abandoned the workflow I was using that was forcing me to select frame ranges and use different files. Now I just use Blender and get a single file out. That fixed a lot of issues.

What I’m stuck on now is getting additive animations to work. I’ll try doing a repro in the playground like you suggested and come back.

Okay, here we go: [https://playground.babylonjs.com/#6I67BL#123](https://playground.babylonjs.com/#6I67BL#123)

If you uncomment line 27 the mesh vanishes, presumably transformed offscreen. Is there a reason why?

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [June 15, 2021, 3:14pm UTC](https://forum.babylonjs.com/t/animation-weighting-issues/21363/4 "2021-06-15T15:14:58Z")

</div>

@Evgeni_Popov do you mind having a look pretty please?

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [June 15, 2021, 5:02pm UTC](https://forum.babylonjs.com/t/animation-weighting-issues/21363/5 "2021-06-15T17:02:55Z")

</div>

I noticed calling `onBeforeAnimation` make it work:

[https://playground.babylonjs.com/#6I67BL#129](https://playground.babylonjs.com/#6I67BL#129)

Let me know if it is the right fix.

---

<div class="post-metadata">

**Author:** ![Antidamage](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/antidamage/32/19857_2.png) [@Antidamage](https://forum.babylonjs.com/u/Antidamage)\
**Post date:** [June 15, 2021, 9:36pm UTC](https://forum.babylonjs.com/t/animation-weighting-issues/21363/6 "2021-06-15T21:36:52Z")

</div>

Yes! Two things actually: in my working copy I was trying to make both animations additive, which caused the mesh to disappear as I guess there was no base animation. There’s also some stuff with magic numbers and single-frame GLTF animations.

Thanks everyone, made a lot of progress last night.

---

<div class="post-metadata">

**Author:** ![Antidamage](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/antidamage/32/19857_2.png) [@Antidamage](https://forum.babylonjs.com/u/Antidamage)\
**Post date:** [June 15, 2021, 11:57pm UTC](https://forum.babylonjs.com/t/animation-weighting-issues/21363/7 "2021-06-15T23:57:15Z")

</div>

I’ve managed to move the progress into my working copy.

Now when I set the weight of the additive animation it’s pretty much binary. Any value over 0.0 applies it 100%, but I can see that the weight is between 0.0 and 1.0. I didn’t have this issue with the test mesh, so it’s probably a mesh problem.

My additive animation is designed to scale the limbs of the skeleton larger but it’s also based on the idle pose rather than a T-pose. Could that cause that behaviour?

Edit: okay it’s not the T-pose thing.

So it looks like that even though the animation is additive, it’s not behaving as if it’s additive. On top of that the weight is doing the above strange behaviour.

Here’s the mesh: [https://github.com/antidamage/Filestore/raw/main/Hipster.glb](https://github.com/antidamage/Filestore/raw/main/Hipster.glb)

Edit: you can see it in the playground here: [https://playground.babylonjs.com/#6I67BL#157](https://playground.babylonjs.com/#6I67BL#157)

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [June 16, 2021, 12:50pm UTC](https://forum.babylonjs.com/t/animation-weighting-issues/21363/8 "2021-06-16T12:50:46Z")

</div>

@Evgeni_Popov I am running out of idea on this one, would be amazing if you could have a look 🙂

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [June 16, 2021, 4:53pm UTC](https://forum.babylonjs.com/t/animation-weighting-issues/21363/9 "2021-06-16T16:53:34Z")

</div>

Will have a look as soon as possible but I want to finish my current PR/doc first while it is fresh in my mind (else it will still take hours before I’m up to speed).

---

<div class="post-metadata">

**Author:** ![Antidamage](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/antidamage/32/19857_2.png) [@Antidamage](https://forum.babylonjs.com/u/Antidamage)\
**Post date:** [June 16, 2021, 8:56pm UTC](https://forum.babylonjs.com/t/animation-weighting-issues/21363/10 "2021-06-16T20:56:48Z")

</div>

I think a clue is that it’s definitely to do with the mesh as the XBot.glb file DOES animate smoothly.

---

<div class="post-metadata">

**Author:** ![Antidamage](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/antidamage/32/19857_2.png) [@Antidamage](https://forum.babylonjs.com/u/Antidamage)\
**Post date:** [June 17, 2021, 1:28am UTC](https://forum.babylonjs.com/t/animation-weighting-issues/21363/11 "2021-06-17T01:28:49Z")

</div>

I’ve been making a new mesh and have uploaded it.

I am _very_ interested in why the playground fails to finish loading: [https://playground.babylonjs.com/#6I67BL#157](https://playground.babylonjs.com/#6I67BL#157)

The model is hidden behind the loader and is interactable if you drag the pane over.

In my app the model is present but never displays. It might be one of the animation groups, as bringing up the inspector and fiddling with the two animations can cause the model to appear and disappear in the playground.

Edit: left it alone and after a few minutes it loaded and I couldn’t replicate the earlier behaviour.

---

<div class="post-metadata">

**Author:** ![Antidamage](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/antidamage/32/19857_2.png) [@Antidamage](https://forum.babylonjs.com/u/Antidamage)\
**Post date:** [June 17, 2021, 3:42am UTC](https://forum.babylonjs.com/t/animation-weighting-issues/21363/12 "2021-06-17T03:42:18Z")

</div>

For whatever reason animation weights aren’t working with that file. Fair enough.

I’m now trying to goToFrame() and stop on that frame, and the height animation is an actual animation of the character growing.

Naturally, that also doesn’t work: [https://playground.babylonjs.com/#6I67BL#177](https://playground.babylonjs.com/#6I67BL#177)

It’s a complicated thing. If the animations are left to play, additives work. If the animations are paused, additives seem to not work. goToFrame() works but only if you don’t pause it right after. And the frame ranges are strange, it’s playing an extra frame in the idle loop if left to figure its own frame range out, which is the start of the grow animation, so it glitches.

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [June 17, 2021, 3:12pm UTC](https://forum.babylonjs.com/t/animation-weighting-issues/21363/13 "2021-06-17T15:12:07Z")

</div>



---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [June 18, 2021, 11:40am UTC](https://forum.babylonjs.com/t/animation-weighting-issues/21363/14 "2021-06-18T11:40:02Z")

</div>

See [Additive animations behave very oddly - #3 by Evgeni\_Popov](https://forum.babylonjs.com/t/additive-animations-behave-very-oddly/21077/3) for my findings on another PG having the same problem than you.

Your PG after the changes:

[https://playground.babylonjs.com/#6I67BL#187](https://playground.babylonjs.com/#6I67BL#187)

Note that `setWeightForAllAnimatables(1.0)` must be called after `start` to have an effect.

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [June 18, 2021, 11:40am UTC](https://forum.babylonjs.com/t/animation-weighting-issues/21363/15 "2021-06-18T11:40:04Z")

</div>



---

<div class="post-metadata">

**Author:** ![Antidamage](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/antidamage/32/19857_2.png) [@Antidamage](https://forum.babylonjs.com/u/Antidamage)\
**Post date:** [June 20, 2021, 9:29pm UTC](https://forum.babylonjs.com/t/animation-weighting-issues/21363/16 "2021-06-20T21:29:34Z")

</div>

That did actually fix it, thank you! It’s a bit unintuitive to need to start the animation first, but the system seems to be working now.

---

<div class="post-metadata">

**Author:** ![Antidamage](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/antidamage/32/19857_2.png) [@Antidamage](https://forum.babylonjs.com/u/Antidamage)\
**Post date:** [June 21, 2021, 3:59am UTC](https://forum.babylonjs.com/t/animation-weighting-issues/21363/17 "2021-06-21T03:59:56Z")

</div>

The next problem is to do with pausing.

I’m able to start the animation to loop on a single timecode, but this isn’t flawless and various things will cause the animation to jump around (background switching, random CPU lag, etc.)

Even setting a timeout to pause the animation doesn’t work.

By the same token I’ve not been able to get goToFrame() to work.

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [June 21, 2021, 8:35am UTC](https://forum.babylonjs.com/t/animation-weighting-issues/21363/18 "2021-06-21T08:35:15Z")

</div>

You mean starting an animation with the same start and end frame does not work? Do you have a repro?

If the start and end frame is the same the animation should not jump around as it should always be the same.
