Async code not executing in editor if not focused

I’m setting up some baking code to crunch data from our internal maps. It’s plain c# Tasks. Everything works fine with good enough performances, neatly wrapped in the new Progress API.

The issue is whenever Unity loses focus, the process pauses altogether, only resuming when I give Unity focus back.
Is this a known limitation? Is there some Unity API I could use to alleviate this issue? Transitioning to coroutines is out of the question, too bad as the EditorCoroutine package keeps working even when the focus is lost.

Hi! Can you share more info on this? Which Progress Api exactly are you using (we have multiple progress apis, one blocking and one asynchronous)? Is it really the task that doesn’t run? Or just the ui that is not updated correctly, i.e. does the progress go to 100% when the task is done if you focus the window?

Hi, I’m using this Unity - Scripting API: Progress. Don’t know of another one but I’d be curious to get any info on that.

The task indeed doesn’t run, as I have a bunch of logs scattered during the process and they don’t fire up all at once, but successively, when I get back focus to Unity. Focusing the scene view seems to accelerate the whole stuff also, weirdly enough.

Ok, this is indeed the Asynchronous progress API. Do you have the same issue if you just create a task that reports progress, without any actual work? On my side this seems to work.

Yeah it does work.
But the opposite is true to : even without the progress API my tasks get stuck if there’s no focus. The progress API was in fact a way for me to try to fix that (as I thought it would be a more involved API managing the tasks as well).

Bumping it as it’s still a pain for our tools.
Any idea what might be the issue as it’s not the progress API @sebastiengrenier ?

Hi khan-amil,

internally with our test project, if we minimize Unity all tasks finish correctly (even those running in threads). Would it be possible to log a bug (Help → Report a Bug) and attach your project (or a project that can repro the problem) on your side?

Thanks,

Seb

I’m experiencing the exact bug. I thought this might be fixed if I build it, but I still experience same symptom running build

edit: not just async, but the whole scene was not running. It was simply fixed by checking option project setting > player > resolution and presentation > Run In Background