Has the original Animation Helper (BABYLON.Animation.CreateAndStartAnimation) now been completely deprecated ?
Over the Christmas holidays all my scripts that utilised the function have stopped working correctly.
The animation sequence no longer terminates when the target has been reached. It continues to re-trigger indefintely.
After a bit of digging, it appears that the Animation Helper is still a valid function, but the default animation loop modes may have changed. I had the default loop mode set at 0 (which is now ANIMATIONLOOPMODE_RELATIVE), which used to work fine, but I find that I have to change them to 2 (ANIMATIONLOOPMODE_CONSTANT). Anyway, this has fixed my issue, although its going to take a while to change all my scripts
It seems like this is a bug or a breaking change:
Loops modes are:
console.assert(BABYLON.Animation.ANIMATIONLOOPMODE_RELATIVE === 0);
console.assert(BABYLON.Animation.ANIMATIONLOOPMODE_CYCLE === 1);
console.assert(BABYLON.Animation.ANIMATIONLOOPMODE_CONSTANT === 2);
Whereas this commit sets
//From
animation.loopMode === 1
//To
animation.loopMode !== Animation.ANIMATIONLOOPMODE_CONSTANT // 2!!
cc @sebavan
Yup the commit was intented to ensure that only constant (which stops at the end of the first run) so value 2 does not loop the animation.
Before only cycle would loop which was preventing the other animation modes like relative, relative from current and yoyo to loop.
It is a bug fix related to Loop Mode Yoyo, Relative, Relative Current Not Working With CreateAndStartAnimation Method
Thanks so much for this. This explains the problem but I’m struggling to figure out “How to fix?”.
This can be set inside of the Animation
like this, Babylon.js Playground
But how do you set it this via the CreateAndStartAnimation
? Can you give me a code line example?
If you have
var panToObj = BABYLON.Animation.CreateAndStartAnimation('move', cam, 'target', speed, frameCount, cam.target, pos, 0, ease, targAnimEnded);
then where do you set the loopMode
?
I can’t seem to find an example of this in the docs.
In your example the following part of the call is the loop mode:
which is defined like this:
Where those values are:
So 0 means relative which is intented to loop so in your case use 1 for constant.
Thanks. I think I got this from the text above. My question was where do you change the loop value? I think it’s clear that you need to change the values. And I get that the values pertain to different loop modes. What method or argument do you call to change it? Do you really need to create a new Animation()
or can you set the loop value when you call
CreateAndStartAnimation
? And if so, what does that look like in code?
Its the 8th parameter of the function: Babylon.js docs
In your example you would change the 0 between pos and ease to something else 0-4 or you can import the variables that define these values and do this
import { Animation } from '@babylonjs/core';
var panToObj = BABYLON.Animation.CreateAndStartAnimation('move', cam, 'target', speed, frameCount, cam.target, pos, Animation.ANIMATIONLOOPMODE_CONSTANT, ease, targAnimEnded);
Thanks! @sebavan had the answer all along. The value 0
is the one that I need to change. For some reason I was looking here Animation | Babylon.js Documentation, and didn’t assume to scroll down to the CreateAndStartAnimation
section. Cheers!