Search Unity

Question Is there a realtime delay for async await?

Discussion in 'Testing & Automation' started by SoftBulb, Oct 9, 2022.

  1. SoftBulb

    SoftBulb

    Joined:
    Apr 20, 2022
    Posts:
    6
    Is there a way to use async await in a real-time?

    Task. delay's time is keep on passing when I pause the game unlike WaitForSecondsrealtime

    Any help would be appreciated! :)
     
  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    5,892
    async await can be used in the context of Unity, yes. And given that Unity is for making realtime apps (such as video games) that should answer your question. If not, please provide more context. ;)

    async await works independently from Unity's other systems, such as the Time class and coroutines and "yield new WaitForWhoKnowsWhat()". The former is true background processing, coroutines are simply methods that are called at certain points during each update cycle, with yield statements allowing you to postpone resuming the execution of the coroutine method at the point where it yielded, by providing a condition such as "wait for end of frame" or "wait for 2 seconds in real time". Here, "real time" means the time that passes regardless of whatever time step is currently set in Unity that affects processing speed (including pausing the game if time step is 0). Async await completely ignores all of this timing done by Unity because it is a general C# background processing concept.
     
  3. SoftBulb

    SoftBulb

    Joined:
    Apr 20, 2022
    Posts:
    6
    Thank you for the replay! I guess I said it in reverse. I need to make await async to not move the time while the game is paused. :)