Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

Bug Async code not executing in editor if not focused

Discussion in 'Editor & General Support' started by khan-amil, Sep 2, 2022.

  1. khan-amil

    khan-amil

    Joined:
    Mar 29, 2012
    Posts:
    186
    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.
     
  2. sebastiengrenier

    sebastiengrenier

    Unity Technologies

    Joined:
    Jun 11, 2019
    Posts:
    70
    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?
     
  3. khan-amil

    khan-amil

    Joined:
    Mar 29, 2012
    Posts:
    186
    Hi, I'm using this https://docs.unity3d.com/2022.1/Documentation/ScriptReference/Progress.html. 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.
     
  4. sebastiengrenier

    sebastiengrenier

    Unity Technologies

    Joined:
    Jun 11, 2019
    Posts:
    70
    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.
     
  5. khan-amil

    khan-amil

    Joined:
    Mar 29, 2012
    Posts:
    186
    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).
     
  6. khan-amil

    khan-amil

    Joined:
    Mar 29, 2012
    Posts:
    186
    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 ?
     
  7. sebastienp_unity

    sebastienp_unity

    Unity Technologies

    Joined:
    Feb 16, 2018
    Posts:
    92
    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