question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Request: Remove or fix `UniTask.WaitForEndOfFrame`

See original GitHub issue

From README:

await UniTask.WaitForEndOfFrame() is not equivalent to coroutine’s yield return new WaitForEndOfFrame(). Coroutine’s WaitForEndOfFrame seems to run after the PlayerLoop is done. Some methods that require coroutine’s end of frame(ScreenCapture.CaptureScreenshotAsTexture, CommandBuffer, etc) do not work correctly when replaced with async/await. In these cases, use a coroutine instead.

This caused huge problems for us, as we had assumed that UniTask methods are one-to-one equivalents to Unity’s. Given that Unity’s WaitForEndOfFrame exists primarily to serve ScreenCapture.CaptureScreenshotAsTexture etc. it is almost guaranteed to cause confusion. In our case CaptureScreenshotAsTexture was failing silently on certain platforms, just creating grey textures.

Is it not possible to have a coroutine run in the background that called yield WaitForEndOfFrame() and then continues the async function containing user code? If not then I suggest this method is deprecated and then either renamed or removed completely.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
neuecccommented, Mar 2, 2022

I’ve add UniTask.WaitForEndOfFrame(MonoBehaviour), it reuse task and coroutine so more lightweight than standard coroutine. It will release soon.

0reactions
rhys-vdwcommented, Mar 21, 2022

Great solution, thanks @neuecc.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Scripting API: WaitForEndOfFrame
Switching from the Game view to the Scene view causes WaitForEndOfFrame to freeze. It only continues when the application switches back to the...
Read more >
Cancel async task: best practice?
Hi, I started working with UniRx.Async replacing coroutines with async/await methods. This is a design pattern question about cancelling ...
Read more >
UniTask v2 — Zero Allocation async/await for Unity, with ...
When the call completes(GetResult), it returns to the pool. This completely removes Task and state machine related allocations. As a limitation, ...
Read more >
6点/UniTask
If you want to change custom beavhiour, set action to UniTaskScheduler.UnobservedTaskException. If you want to cancel behaviour in async UniTask method, throws ...
Read more >
c# - How do I avoid async void?
So I suppose this code is executed on the Main, UI Thread. Let's step into what your code do in details, when executing...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found