LitMotion.Animation has inconsistent behaviour between Editor and build
I have a UI panel that I want to expand and collapse (see following video)
https://github.com/user-attachments/assets/e8d5d39f-da1a-42db-a12a-4dc5234e983b
This is my code:
[SerializeField] private LitMotionAnimation _expandAnim;
[SerializeField] private LitMotionAnimation _collapseAnim;
private async void Expand()
{
_expandAnim.Stop();
await UniTask.NextFrame();
_expandAnim.Play();
while (_expandAnim.IsPlaying && !destroyCancellationToken.IsCancellationRequested)
{
await UniTask.NextFrame();
}
}
private async void Collapse()
{
_collapseAnim.Stop();
await UniTask.NextFrame();
_collapseAnim.Play();
while (_collapseAnim.IsPlaying && !destroyCancellationToken.IsCancellationRequested)
{
await UniTask.NextFrame();
}
}
I first stop the animation so it begins from the beginning in case it was played before already, since I will play this animations repeatedly.
I had to add the await UniTask.NextFrame(); to wait for one frame after stopping because it solved an issue I was having with one of the animations not playing correctly.
This now works fine on Editor but in the builds it doesn't. The Collapse is triggered but it stays opened (see following video)
https://github.com/user-attachments/assets/55725fa5-2a54-4ed1-a1e5-f0e302d0473e
I appreciate any guidance on what I'm doing wrong, thanks in advance.
Did you try assigning the animation to MotionHandle, then using TryComplete() or TryCancel() before the next animation is called? Personally, I'd go something like this;
if(motionHandle.IsPlaying()) motionHandle.TryComplete();
motionHandle = _expandAnim.Play();
@dgkn94 thanks, will test your solution 👍