Комментарии:
Wow , as someone who knows and uses Javascript this is so amazing, definitely reminds me of promises!!! Thank you!! Is this in current unity 2022??
ОтветитьExcellent tutorial! was wondering how do you cancel a task?
ОтветитьThis async thing sucks bad, you find hidden errors everywhere, I expend half a day trying to know why I could not excecute a fucking "Random.Range"! It turns out, you cannot call this and lots of other functions from outside of the main thread!
If you're planning to use async funcs, really really test before if this is going to be useful, else, run!
i would love to see coroutines hot mom
ОтветитьClean video. Thanks a lot didnt know this thing even existed less go
ОтветитьI don't get it. I didn't everything right, why is my Task doing random errors in different lines of code. I've reviewed everything, and it should work as fine, but nothing is doing what it's supposed to. The Task.WhenAll is making an error and is not even waiting. It's just throwing a null exception which is confusing
ОтветитьSo when should I use coroutines instead?
Ответитьcan you link the back ground music
ОтветитьNice, I didn't know about GetAwaiter() - that's going to resolve some warnings in projects I worked on prior to exploring gaming. Question: Why are you serializing the fields that you do? I'm glad you mentioned WebGL; I just started my first game and didn't like the coroutine approach at all, and was actually hoping I could use async await instead (which led me here). But, I had already selected WebGL and would have strongly disliked having to re-refactor the code! Thanks for the tutorials, they're a great help!
ОтветитьCool Beenz
ОтветитьA disadvantage af tasks is that they're slightly harder to cancel and aborting should that case arise, versus coroutines which is pretty easy to stop. ofc. it is still possible but it requires a bit more effort. I'm also pretty sure unless recently added that multithreaded work load with parallelfor could cause some issues if it is used to call unity's methods directly. It is a shame it isn't supported on all platforms tho, it is usually a powerful tool for a few specific things for sure.
ОтветитьOmg, i was frustrated on why my WebGL game's asyncs were not working. I thought I was a noob (turns out I am still) but now I have realized they don;'t work in webgl so gotta stick with coroutines.
man webgl has many issues.
For those having problem with the application still running when game is stopped, Ive created this small class that detects when the application is closed,
then use it with your "while ( ) code, like this►► While (!GetCancelToken && "add your logic here" ) { "continue your code normally }
public static class ApplicationQuit {
static CancellationTokenSource cancelToken = new CancellationTokenSource();
[RuntimeInitializeOnLoadMethod]
static void RunOnStart() {
Application.quitting += OnApplicationQuitting;
}
static void OnApplicationQuitting() {
Debug.Log("Game is about to stop or close.");
cancelToken.Cancel();
}
public static bool GetCancelToken() {
return cancelToken.IsCancellationRequested;
}
}
what about UniTask ?
ОтветитьThank you.
ОтветитьSo I run into an issue using async await instead of coroutines where thing continue to happen while in the editor. For example if I use async await to start a countdown for an enemy to explode. It may explode multiple times and it may play sounds while game is not running in the editor...so, wth??
Ответитьienumerator - hard to spell
async - easy to spell
i wish you make more advanced tutorials about asyncs <3
ОтветитьFor newbie Unity C# community, can't be without you
ОтветитьThat was my first time I easily used a hard topic, thank you. I will tell everybody how you meme'd a really good topic(Of course usage too). I will watch every use case video you will release. Hope there will be more meme intros too.
ОтветитьShould stay away from async to eliminate garbages.
ОтветитьNice work covering this subject and displaying the mulitple ways async/await can be used. Even a year+ on after the release of your video, its still a gold nugget!
ОтветитьYour example of running functions sequentially is literally the same as coroutines, making the BeginTest function async is the same as calling a base coroutine that calls other coroutines. I see the benefit of async but you spent a bit of time explaining how messy it is with coroutines only to write identical code with async
ОтветитьHeyo great video! I'm creating a game with a chunking system similar to minecraft (except the map is static width&height) so no infinite loading. I've been using coroutines to Load/Save chunks but I was noticing like a 0.005ms delay (so a loss of mouse control during that time), I've added the async way instead and it seems to be gone, is that the right idea? The chunks are now loading while moving the camera I think but its so hard to tell as its so quick anyway.... :D
ОтветитьWhen I first learned about Coroutines it was ground breaking, the peak of technology for my silly indie brain.
Now I'm finding out about async/await/tasks and it's just wonderful. Truly amazing to see how there's always something new to learn.
And then you have COD scripting which has simple "wait" and "endon" functions. As simple as it gets.
ОтветитьGreat stuff. I have a question. Do you have in plans maybe another video about async await? Like for example video about cancellation tokens or the difference between C# Taks and UniTaks?
Ответить🎉
Ответитьnot supporting WebGL is a really big disadvantage...Any reason for it?
ОтветитьNo, you monkey, you use the appropriate tool for the job. The job... SYSTEM is Unitys' way of multithreading.
1. Unity already uses the job system internally and reserves threads equal to the amount of logical cores available on the system. If you use another multithreading library (async/await is a library built into the language) you will run into decreased performance due to even more frequent context switches. If the goal of multithreading is performance, using async/await instead of the job system contradicts the original goal of using it in the first place
2. The job system is thread safe, async/await is not. If your goal with this video is to teach some newbie who just wants to build the next WoW killer about "the easy way to do multithreading", then it's both the wrong audience picked and the wrong tool taught, big time.
But I didn't expect much expertise from someone who uses 'var' or the following code "style":
class X { // < this was proven to be less readable
int thisSucks;
// what is this empty line doing here
}
All in all, 2/5
I had this video recommended to me some time ago but I couldn't find it. So that I searched for coroutine hot sister...then realized the wording's bit of a mess xD
ОтветитьIs anybody else having problems with async/await and Android? My builds silently fail now after change a couple coroutines to asyncs, No problems in the editor or non-mobile versions
Ответитьthanks a lot !
ОтветитьI will definitely have to keep this one in mind! 👍
ОтветитьThe problem I am getting with this that Coroutines do not have is the when making a Task for an anonymous reference that should only exist once.
For the Coroutine I just needed to make a dictionary, made the key something that identified the reference and ran the coroutine associated with that key after checking if that key was already active.
I can't do that with Tasks, I tried using Func<Task> but that's a not go as well.
I think it's worth mentioning that async/await continues to work in the editor even after the game has stopped, unless you set an exit condition that takes this into account. Can lead to unexpected results, especially if moving, adding or removing scene objects, playing sound, etc. occurs inside asynchronous functions.
ОтветитьI have a question, what is the downside of using Async compare to Coroutine ? is it taking a lot of resource ?
ОтветитьFound this video awhile ago, but I keep coming back because I forget the snytax or where in my code to implement the async or await functions.
Thank you so much for this video as it really helped me on my projects and will continue to help me on future Unity projects.
Thanks for the tutorial. Question, when is it a bad idea to await an async method? If I do it on Update it will spawn a call every frame, so seems like it makes more sense to make use of it on functions that get called less frequently. When can it seriously affect performance?
ОтветитьNice detailed and simplified tutorial
Ответитьcoming from a javascript background and being familiar with Promises (and having trouble wrapping my mind around coroutines) this video is a lifesaver! thank you so much
ОтветитьCan you please make advance tutorial for async/await methods? Also Need more examples too!! Thanks for tutorials! It helped a lot.
ОтветитьI know you have a background soundtrack. It kind of disturbed me when I heard it and thought where it came from? I don't like background noise.
ОтветитьMake me question why I learned coroutine at all ????
ОтветитьHello, I'm trying to use async/Task to ask the player to click an object, retrieve the GameObject and work with it. There is a video where I can learn about it?
ОтветитьI found this very usefull, and i can say that it really worths, not only for the time you spent making it, but because we can realize the quality of this production when you read the meticulous observations that other also experienced people make in the comments.
Ответить