'Issues with WebGL animations

During gameplay I fire off a animation and I check if it's been completed to continue on with the game with this logic: ` protected async Task IsAnimFinished(string name) { var isFinished = false;

     while (!isFinished)
     {
         if (animator.GetCurrentAnimatorClipInfo(0)[0].clip.name == name && !animator.IsInTransition(0) && animator.GetCurrentAnimatorStateInfo(0).normalizedTime >= 0.98f)
         {
             isFinished = true;
         }
         await Task.Yield();
     }
     return;
 }

`

The issue happens when I build and host the game, the isFinsihed will not set to true when I change the tab (game instance) into a background process. I initially thought that animations are being culled so I set all animations to "Always animate" and never cull, I also have camera culling off.

But this is continuing to cause issues. I'm also noticing that in the background process it will run the logic for the animation but it won't actually play it, meaning if I have a character standing there and getting hit, his health will be lowered (to death) but the character will still be receiving hit animations, and then other instances they will get locked in the while loop.

Is there anything I'm missing that could cause this?



Solution 1:[1]

Are you sure you didn't run something on a thread other than the main? If you did this, it's the problem. Because unity WebGL doesn't support multithreading.

The following link could be helpful: https://forum.unity.com/threads/async-await-and-webgl-builds.472994/

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Abolfazl