Cysharp/UniTask

Calling UniTask.Delay throw an error in the WebGL build

AndreiUsoltsev opened this issue · 2 comments

Unity version 2022.2.18. Platform WebGL.
Calling the Delay method in any part of the code throws a NullReferenceException error.
The error is only in the build. It's not in the editor.

Build.framework.js:2800 NullReferenceException: Object reference not set to an instance of an object. at Cysharp.Threading.Tasks.PlayerLoopHelper.AddAction (Cysharp.Threading.Tasks.PlayerLoopTiming timing, Cysharp.Threading.Tasks.IPlayerLoopItem action) [0x00000] in <00000000000000000000000000000000>:0 at Cysharp.Threading.Tasks.UniTask+DelayPromise.Create (System.TimeSpan delayTimeSpan, Cysharp.Threading.Tasks.PlayerLoopTiming timing, System.Threading.CancellationToken cancellationToken, System.Int16& token) [0x00000] in <00000000000000000000000000000000>:0 at Cysharp.Threading.Tasks.UniTask.Delay (System.TimeSpan delayTimeSpan, Cysharp.Threading.Tasks.DelayType delayType, Cysharp.Threading.Tasks.PlayerLoopTiming delayTiming, System.Threading.CancellationToken cancellationToken) [0x00000] in <00000000000000000000000000000000>:0 at Cysharp.Threading.Tasks.UniTask.Delay (System.TimeSpan delayTimeSpan, System.Boolean ignoreTimeScale, Cysharp.Threading.Tasks.PlayerLoopTiming delayTiming, System.Threading.CancellationToken cancellationToken) [0x00000] in <00000000000000000000000000000000>:0 at Cysharp.Threading.Tasks.UniTask.Delay (System.Int32 millisecondsDelay, System.Boolean ignoreTimeScale, Cysharp.Threading.Tasks.PlayerLoopTiming delayTiming, System.Threading.CancellationToken cancellationToken) [0x00000] in <00000000000000000000000000000000>:0 at PuzzleMode.BootStrapper.Init () [0x00000] in <00000000000000000000000000000000>:0

You are likely running into the same issue I did (see here:
#483)

Likely you are using UniTask before its playerloop is initialized. In the readme under playerloop there are examples of how to deal with this if it is related to timing or ECS, but there are some issues with the description/fixes, that's why I opened my issue above.

From the stack trace, Looks like it is likely that UniTask is used before BeforeSceneLoaded .

Therefore, maybe it is not a question of UniTask.Delay,

I think it is hard to fix UniTask side is because the key point is at what timing UniTask.Delay was used.
For WebGL builds, is there any particular reason why UniTask must be used before scene loading?
If so, it would be helpful to know about it.

#483 #489 may be helpful.