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 ...
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 ...
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 ...
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 ...
3
votes
Using Async Await in Unity
You can have a coroutine runner MonoBehaviour that runs coroutines defined elsewhere. For example:
...
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 ...
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 ...
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:
...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
1
vote
Instead of using yield wait for seconds can I use a UI button for async?
Just use a boolean flag.
...
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 ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
async × 20unity × 16
c# × 10
scene × 6
loading × 4
multithreading × 3
scenemanager × 3
c++ × 2
preload × 2
input × 1
webgl × 1
lua × 1
gpu × 1
coroutines × 1
lag × 1
unity-webgl × 1
profiler × 1
assetbundle × 1
addressable × 1
c++cli × 1
thread × 1
array × 1
c++-winrt × 1