Skip to main content
10 votes

Should I use Async & Await, instead of Coroutines, in Unity?

In contrast to Evorlor's answer, here are some good reasons to use Coroutines: They've been the standard solution in Unity for many years and anyone else you bring onto the team should already be ...
Kevin's user avatar
  • 6,854
4 votes
Accepted

Is this code using Awaitable correct?

Summary 1. Is my code correct according to the best standards? Not quite correct. This implementation doesn't handle exceptions properly and doesn't stop when object is disabled or destroyed. The ...
Vladimir's user avatar
  • 336
4 votes

How would you write a multithreaded gameloop in C++20 (+) or C++/WinRT?

When you are separating a game engine into threads, then there are two main concerns: Each worker-thread should have roughly the same amount of work to do Avoid communication and data sharing between ...
Philipp's user avatar
  • 122k
4 votes

Unity is single thread then why unity webgl says asset bundles are load in main thread

Unity does run multiple threads, but NOT in WebGL. Standard unity and most of it's target platforms that support multithreading will use multithreading. If you've ever had your game freeze and heard ...
gjh33's user avatar
  • 691
3 votes

Using Async Await in Unity

You can have a coroutine runner MonoBehaviour that runs coroutines defined elsewhere. For example: ...
Ed Marty's user avatar
  • 5,249
2 votes
Accepted

Instead of using yield wait for seconds can I use a UI button for async?

Rather than running this as a coroutine, ticking every frame waiting to see if the button is pressed, I'd just store the AsyncOperation and let the button give it a kick when the player finally ...
DMGregory's user avatar
  • 136k
2 votes
Accepted

My script to play the intro scene the first time the player hits play from the main menu wont work

I'm unable to reproduce this problem. In my tests with this code, the first time I click the button I go to the "Intro" scene. Any subsequent run of the game, I go to the scene named in the ...
DMGregory's user avatar
  • 136k
2 votes

Animate Loading Screen During CPU-Heavy Scene Load

As mentioned in the comments, you can use an ordinary variable to pass around information about when the generation is done. Here's one way to do it: ...
DMGregory's user avatar
  • 136k
2 votes

Preload multiple scenes at the same time and activate them on demand in Unity. [Unity, async, simultaneous]

Short answer Currently we can't do that in certain cases. Long asnwer AsyncOperation.allowSceneActivation tells us: When allowSceneActivation is set to false then ...
Candid Moon _Max_'s user avatar
2 votes
Accepted

How to make a text-based game with timer systems

In a standard engine, dt represents the time in milliseconds since the last frame. In a text adventure, dt can represent the ...
DragonDePlatino's user avatar
2 votes

How to make a text-based game with timer systems

You can try adapting main loops from graphical video games. Have your main loop run as often as your logic rate. At each iteration, test if you have received any input from the terminal. I do not know ...
Poopoo's user avatar
  • 21
1 vote

UI mask and elements not visible after Async scene change

I was having the same problem with the inverted mask, and found this thread in Unity Forums, so I tried what styrbo suggested. But didn't work initially, then I tried changing maskable to false and ...
brohr's user avatar
  • 111
1 vote

Should I use Async & Await, instead of Coroutines, in Unity?

Should I use Async & Await or Coroutines? You should use Async & Await. Coroutines were Unity's solution to running multiple simultaneous processes at a time when the version of C# it ...
Evorlor's user avatar
  • 5,840
1 vote

Instead of using yield wait for seconds can I use a UI button for async?

You can use WaitWhile to define a condition for the coroutine's yield. Something like this could work, with a button configured to update the value of ...
Joe's user avatar
  • 435
1 vote

Instead of using yield wait for seconds can I use a UI button for async?

Just use a boolean flag. ...
House's user avatar
  • 73.3k
1 vote

Unity is single thread then why unity webgl says asset bundles are load in main thread

What Unity doesn’t support in JavaScript is multiple threads. So there is only ever the single main thread of execution. If there were multiple threads, Unity would be able to run LZMA decompression ...
Ed Marty's user avatar
  • 5,249

Only top scored, non community-wiki answers of a minimum length are eligible