I'd much prefer to not go through my entire project to replace all of my async/awaits with coroutines... Is there something I can replace await with which works in webgl?
How exactly? A simple await Task.Delay() causes a threading error. For example, a project with just this one script will fail: Code (CSharp): public class AwaitTest : MonoBehaviour { public GameObject Ball; void Start() { Drop(); } private async void Drop() { while (true) { Instantiate(Ball, Vector3.zero, Quaternion.identity); await Task.Delay(500); } } }
Hi I am currently using async await for API calls along with Unity Web Request should I avoid it if I am planning for deploying on WebGL?
Yes You should avoid it. Because at the end it will not work in WebGl . I have faced similar issue. Use UniTask Instead.
Aync/Await absolutely works with WebGL, it's System.Threading that doesn't. Also, the new 2023.1 "Awaitables" (so await Awaitable<T> rather than Task<T>) absolutely work with WebGL, and will let you. await Awaitable.WaitForSecondsAsync() works in WebGL, and will let you do the same as a task.delay. https://docs.unity3d.com/2023.1/Documentation/ScriptReference/Awaitable.WaitForSecondsAsync.html Bonus points for the fact that using Awaitable<T> means that async/await actually works sanely in the editor. Don't await BackgroundThreadAsync() though, that just drops off a cliff, since Awaitable doesn't change the fact that threads don't exist in WebGL.
I can also confirm async/await works in my projects' WebGL builds without issue (first started using in 2022 LTS and am still using in 2023.3 alphas).