UniTask icon indicating copy to clipboard operation
UniTask copied to clipboard

InvalidOperationException: Target playerLoopTiming is not injected

Open crisdesivo opened this issue 1 year ago • 1 comments

When using UniTask in Unity 2022.3.41.f1 for WebGL export I get the following error:

InvalidOperationException: Target playerLoopTiming is not injected. Please check PlayerLoopHelper.Initialize. PlayerLoopTiming:Update
  at Cysharp.Threading.Tasks.PlayerLoopHelper.ThrowInvalidLoopTiming (Cysharp.Threading.Tasks.PlayerLoopTiming playerLoopTiming) [0x00000] in <00000000000000000000000000000000>:0 
--- End of stack trace from previous location where exception was thrown ---

I added await UniTask.Yield(PlayerLoopTiming.Initialization); before starting the UniTask and it never proceeds.

It works without any issue for Windows/Linux export and also in the editor.

crisdesivo avatar Jan 03 '25 21:01 crisdesivo

There are occasional reports of automatic injection not working in WebGL. While the exact details are unclear... As a workaround, I think it would work if you explicitly call Initialize before your product code.

var playerLoop = PlayerLoop.GetCurrentPlayerLoop();
PlayerLoopHelper.Initialize(ref playerLoop);

neuecc avatar Jan 06 '25 10:01 neuecc

This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 30 days.

github-actions[bot] avatar Jul 06 '25 00:07 github-actions[bot]