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. Dismiss Notice

Unity Future .NET Development Status

Discussion in 'Experimental Scripting Previews' started by JoshPeterson, Apr 13, 2021.

  1. Laicasaane

    Laicasaane

    Joined:
    Apr 15, 2015
    Posts:
    288
    A vote for something shorter. Please, my own code is already verbose enough. Official APIs should be concise and short if possible.
     
    M_R and Elringus like this.
  2. WinterboltGames

    WinterboltGames

    Joined:
    Jul 27, 2016
    Posts:
    257
    I really hope that a shorter name like UnityTask for example will be used instead of AwaitableCoroutine.
     
  3. TieSKey

    TieSKey

    Joined:
    Apr 14, 2011
    Posts:
    219
    Everyone is entitled to their opinion and I respect that but for the love of whatever god I will never understand the itch for shorter code.... :shrugh:
     
  4. WinterboltGames

    WinterboltGames

    Joined:
    Jul 27, 2016
    Posts:
    257
    It is not just about shorter code, it is about sensible code. AwaitableCoroutine (in my opinion) gives the false impression that it is related to Coroutine. Something like UnityTask, on the other hand, immediately makes it clear to the reader that it is something associated with Task but with Unity things added on top.
     
  5. CaseyHofland

    CaseyHofland

    Joined:
    Mar 18, 2016
    Posts:
    548
    @goldbug if you go up in the forum enough, back in ancient times, I believe it was stated that Unity working with async is its own thing: still works with UniTask, UniTask may still bring added benefit, but the fundamentals of working with async, what you would normally do with UniTask, can now be done with Unity.
     
    goldbug likes this.
  6. CaseyHofland

    CaseyHofland

    Joined:
    Mar 18, 2016
    Posts:
    548
    How do you handle cancellation tokens? Do Objects now have a (public) “isDestroyed” token, or does AwaitableCoroutine fill in some magic token we can’t change?
    My biggest wish for this system was the ability to say “well cancel this task if other object dies”.

    I suppose since it now just works with async, worst case we can wrap AwaitableCoroutine and provide a custom token, but it would be nice to know if Unity provides any quick and easy handles.

    p.s. +1 on renaming to UnityTask, AwaitableCoroutine is a mouthful
     
    WinterboltGames likes this.
  7. Laicasaane

    Laicasaane

    Joined:
    Apr 15, 2015
    Posts:
    288
    cxode, CaseyHofland, Qbit86 and 2 others like this.
  8. CaseyHofland

    CaseyHofland

    Joined:
    Mar 18, 2016
    Posts:
    548
    @Laicasaane thanks can’t wait!

    @simon-ferquel-unity any reason why it’s not in Object? Not judging, but it does seem strange that if it’s Object.Destroy, it’s not Object.destroyCancellationToken, not to mention leaving money on the table. I’m just curious why this decision was made: as I understand it, I still wouldn’t be able to say (minus own implementation) cancel my task if MeshRenderer is destroyed, or GameObject dies, or hell ScriptableObject gets unloaded.
     
  9. TheZombieKiller

    TheZombieKiller

    Joined:
    Feb 8, 2013
    Posts:
    258
    Having a CancellationToken for all UnityEngine.Object-derived classes would be pretty useful, you could then use the Register method to receive a callback for when the object is destroyed: something you could not do previously without hooking C++ functions within the engine. I know I've needed such functionality before when loading assets at runtime (for example, an AudioClip that reads PCM data from a stream -- I want to dispose of that stream if the clip is destroyed).
     
  10. simon-ferquel-unity

    simon-ferquel-unity

    Unity Technologies

    Joined:
    Apr 1, 2021
    Posts:
    65
    It is still AwaitableCoroutine, but 2023.1 is not set in stone, so we can adapt to feedback.
    There are a few things we have considered about the naming that you may want to consider as well for suggestions:
    - not have "Task" in it, as it has lead to so much incomprehension about different kind of async code in C# community before (eg. async IO operations, events etc.). Not that if you take the case of APIs like NextFrame or EndOfFrame or FixedUpdate etc, those are absolutely no tasks at core. Coroutine felts like a good "generic" term to qualify any kind of routine executing aside. I would have loved AsyncOperation (the term chosen in modern Windows APIs for expressing anything that is async) but... it is already takin in Unity world. We could argue that Coroutine is quite overloaded as well in Unity world, so I agree the name is not perfect
    - Hinting at await-compatibility: Unity has demoted await support for so long that we thought developers might like the API to basically tell them "go on, use it, it's ok now!" to feel safer. I could be wrong here so please submit ideas.

    About examples, we are currently in the documentation phase, adding pages about how to best leverage async/await and trying to update all pages about existing async APIs that now have await support - that is long and tedious work.
     
    SpencerGR, cxode and kdchabuk like this.
  11. simon-ferquel-unity

    simon-ferquel-unity

    Unity Technologies

    Joined:
    Apr 1, 2021
    Posts:
    65
    That is actually a good one, and there is an answer to that, which is scalability: whenever you introduce per-object callbacks (as CancellationToken in that case is basically a glorified OnDestroy callback), you have overhead on pretty much every object destruction. Even if there is no usage of the CancellationToken, we still have some code like
    Code (CSharp):
    1. if(destroyCancellationTokenIsInUse){
    2.   RaiseCancellation();
    3. }
    on every destroy coroutine. MonoBehaviour already had some more-complex than average destruction logic so the overhead was basically noise here. But putting the cancellation token on every UnityObject (and there are a lot of them, some being not even exposed to user code) would have had too much overhead unfortunately.
     
    MasonWheeler, cxode, kdchabuk and 2 others like this.
  12. Laicasaane

    Laicasaane

    Joined:
    Apr 15, 2015
    Posts:
    288
    I think you should explain more about its nature so we can brainstorm a better name if any.
     
  13. simon-ferquel-unity

    simon-ferquel-unity

    Unity Technologies

    Joined:
    Apr 1, 2021
    Posts:
    65
    So AwaitableCoroutine type is an abstraction between "anything async" in Unity and the async/await machinery:
    - It allows us to expose async native code into something you can use with await (current implementation of await for frame events awaitables and AsyncOperation classes is mostly done in native, and we raise successfull completion / exception callbacks required by await directly from native code)
    - It also allows us to expose managed async code that was not awaitable before into something awaitable as well (e.g., UnityEvent support is done like that)
    - Finally, it can be used instead of Task/ValueTask as an async return type which behaves a bit differently than builtin Task/ValueTask
    - It executes continuations synchronously - instead of scheduling them for next frame
    - It supports a single awaiter for better scalability (trying to await twice on the same task will fail)
    - It takes some shortcuts in how we capture the execution context (as we consider it wont be used on a server serving multiple users, we dont capture the full secutity context of the caller thread for example).​

    So the AwaitableCoroutine name is exactly describing that:
    - any kind of coroutine (running a background task, waiting on en engine event, waiting on a user interaction, waiting on an asynchronous IO,...)
    - that can be "awaited"
     
    tomfulghum, aizuon and Laicasaane like this.
  14. simon-ferquel-unity

    simon-ferquel-unity

    Unity Technologies

    Joined:
    Apr 1, 2021
    Posts:
    65
    Oh and also, it is very specific to Unity, as the shortcuts we take are valid because we are in the context of a Unity game loop.
     
    tomfulghum and Anthiese like this.
  15. Saniell

    Saniell

    Joined:
    Oct 24, 2015
    Posts:
    167
    At least you could rename it to AsyncCoroutine which is something not as painful to type out. "Awaitable" has letters all over keyboard for common use really horrible choice imo

    Does this mean it is impossible to switch this Coroutine to background thread like Unitask allows you to?
     
  16. simon-ferquel-unity

    simon-ferquel-unity

    Unity Technologies

    Joined:
    Apr 1, 2021
    Posts:
    65
    Having await support means you can mix and match any await compatible construct such as
    Code (CSharp):
    1. async AwaitableCoroutine<int> DoSomethingAsync(CancellationToken token) {
    2.   await SomeUnityAsyncOperation(token);
    3. // offload some heavy operation
    4.   var value = await Task.Run(() => { return 42;});
    5.   Debug.Log(value);
    6.   return value;
    7. }
    So that way you can have all of them (not paying for default task scheduling that schedule continuations asynchronously by default while still being able to use Task.Run to offload work and synchronize back to the main thread)
     
    stonstad likes this.
  17. KuraiAndras

    KuraiAndras

    Joined:
    Aug 23, 2021
    Posts:
    10
    How about the .ConfigureAwait(false) behaviour after the Task.Run ?
     
  18. simon-ferquel-unity

    simon-ferquel-unity

    Unity Technologies

    Joined:
    Apr 1, 2021
    Posts:
    65
    it would work as well, but you would not go back to the background thread (meaning "DoSomethingAsync()" would complete on a background thread as well which may or may not be what you want)
     
  19. Saniell

    Saniell

    Joined:
    Oct 24, 2015
    Posts:
    167
    Does this mean we could sync background thread with Update cycle using wait await NextFrame() or something?

    Also are you planning to provide APIs to come back to main thread like UniTask does?
    Code (CSharp):
    1.  
    2. // Multithreading, run on ThreadPool under this code
    3. await UniTask.SwitchToThreadPool();
    4.  
    5. /* work on ThreadPool */
    6.  
    7. // return to MainThread(same as `ObserveOnMainThread` in UniRx)
    8. await UniTask.SwitchToMainThread();
    9.  
    If not I hope it could at least be possible to implement yourself? Not like I couldn't survive without this feature but it is rather handy when dealing with file IO like saving the game
     
  20. simon-ferquel-unity

    simon-ferquel-unity

    Unity Technologies

    Joined:
    Apr 1, 2021
    Posts:
    65
    We don't have that in the plans exactly, but using Task.Run and awaiting on it will have the same flow (callback within Task.Run will run in the background thread, while awaiting on it from the main thread will resume execution on next Update). Also, you can continue using UniTask for things not covered by built-in support.
    Our goal here is not to replace UniTask, but to bring the core set of things needed to be await-friendly in the engine itself (mainly being able to have await support for things implemented in native code and having an efficient async return type with defaults that better fit Unity). By doing that there are opportunities to be more efficient, while bringing space for the ecosystem to work on higher level constructs.
     
  21. CaseyHofland

    CaseyHofland

    Joined:
    Mar 18, 2016
    Posts:
    548
    That's a good reason. But because I'm a stickler, I'm gonna throw up one more ball.

    What if you do this?
    Code (CSharp):
    1. internal interface ICancellable
    2. {
    3.     void Cancel();
    4. }
    5.  
    6. internal struct EmptyCancellable : ICancellable
    7. {
    8.     public void Cancel() {}
    9. }
    10.  
    11. internal struct Cancellable : ICancellable
    12. {
    13.     public CancellationTokenSource source;
    14.  
    15.     public Cancellable(CancellationTokenSource source)
    16.     {
    17.         this.source = source;
    18.     }
    19.  
    20.     public void Cancel() => source.Cancel();
    21. }
    22.  
    23. public void Object
    24. {
    25.     private static readonly EmptyCancellable emptyCancellable; // small optimization to only create the EmptyCancellable once. May be part of EmptyCancellable.
    26.  
    27.     private ICancellable _cancellable = emptyCancellable;
    28.     public CancellationToken destroyCancellationToken
    29.     {
    30.         if (_cancellable is not Cancellable)
    31.         {
    32.             _cancellable = new Cancellable(new CancellationTokenSource()); // pseudo-code
    33.         }
    34.         return _cancellable.source.Token; // DEFINITELY pseudo-code :')
    35.     }
    36.  
    37.     void InternalOnDestroy()
    38.     {
    39.         _cancellable.Cancel();
    40.     }
    41. }
    Main points:
    - Only create the CancellationToken when it's requested.
    - No branching or implementation costs (minus a single empty method call) when it's not.

    This would of course be weird if called after the object has been destroyed / in an OnDestroy, but that's why throwing was invented. Or perhaps the token could just be set to true from the get go. Either way, I don't think it's a crime if it's well documented: Renderer.material is of a similar beast, where it does secret dirty-work under the hood.
     
    Last edited: Oct 10, 2022
  22. CaseyHofland

    CaseyHofland

    Joined:
    Mar 18, 2016
    Posts:
    548
    How about AsyncCoroutine? As much as it pains me, UnityTask is off the table if the underlying API is definitely not tasks, that would just lead to confusion about its implementation. But if it's not Task, yet it is async, then AsyncCoroutine seems perfect for it. It seems that what is said here is exactly what you're doing. Even though async is awaitable, awaitable is not async, and AwaitableCoroutine seems to dwindle on its scope.

    I wouldn't worry about it, you have an excellent community both on YouTube and in the forums, as well as great Unite talks highlighting new features for those who will teach the next generation. Heck, the roadmaps too now!

    Plus, can't say I disagree with this:
     
    SpencerGR likes this.
  23. simon-ferquel-unity

    simon-ferquel-unity

    Unity Technologies

    Joined:
    Apr 1, 2021
    Posts:
    65
    I tend to disagree on the "coroutine does not mean async" here. In my understanding (but arguably I am not a native english speaker), a coroutine is someting that runs aside your main routine, which is well, the principal characteristic of async. To me, AsyncCoroutine does not make sense then. I was more expecting something like UnityAwaitable, or something bringing new "kind of synonyms" for coroutines. Maybe UnityFuture ? UnityPromise ? but I am not sure I like them more :D
     
    aburger22, SpencerGR and MasonWheeler like this.
  24. simon-ferquel-unity

    simon-ferquel-unity

    Unity Technologies

    Joined:
    Apr 1, 2021
    Posts:
    65
    First point, we already do that.
    Second point, this is a virtual call on every destruction, basically the same cost as what we are trying to avoid on a per object basis :/
     
    CaseyHofland likes this.
  25. TieSKey

    TieSKey

    Joined:
    Apr 14, 2011
    Posts:
    219
    After reading the rationale, AwaitableCoroutine sounds even better. Naming in code/apis should never be conditioned by the """""cost"""" of typing it... that's an 80's thing when we coded in VIM/Emacs... on any modern IDE we will only type "awa" and autocomplete anyway...

    Clarity and explicitness should be almost always desired.
     
    SpencerGR, KamilCSPS and Qbit86 like this.
  26. CaseyHofland

    CaseyHofland

    Joined:
    Mar 18, 2016
    Posts:
    548
    That's fair enough, but the async keyword in C# world still signals "not run on the main thread", which is as I understand the fundamental difference between Coroutine.

    So maybe what would be really cool is just
    async Coroutine DoSomethingAsync(CancellationToken token)
    , and let the async keyword just specify its awaitable-ness.

    But, alas, that name already exists in the UnityEngine namespace. Yet since we use it with the async keyword and you don't need to specify its Co-ness anymore maybe just...
    async Routine DoSomethingAsync(CancellationToken token)


    I don't even know how I feel about that myself :|

    Nevertheless, I still think
    async AwaitableCoroutine
    is ugly for the same reason, you don't need to specify Awaitable if it's an async method, the compiler already tells us that.

    EDIT:
    And yes, I'm an idiot,
    async AsyncCoroutine
    would have been ugly in hindsight as well :oops:
     
    Last edited: Oct 10, 2022
    SpencerGR likes this.
  27. CaseyHofland

    CaseyHofland

    Joined:
    Mar 18, 2016
    Posts:
    548
    By the by thanks for all the transparency throughout, I know I can get a bit direct in these discussions but I really appreciate them, the attention and involvement from the actual Unity team behind it is why this is the single greatest thread on this forum.
     
    SpencerGR, bdovaz and Saniell like this.
  28. Saniell

    Saniell

    Joined:
    Oct 24, 2015
    Posts:
    167
    Autocomplete is slow and typing by hand if you know what you want to type is usually faster. At least in visual studio it is


    UniRoutine? :rolleyes:
    I dunno, but the fact that there's probably already going to be 'async' near the name is a good touch, didn't think of it... Somehow
     
    JesOb likes this.
  29. TangerineDev

    TangerineDev

    Joined:
    Sep 28, 2020
    Posts:
    122
    So I'll be throwing out some vocabulary so we can decide on a name:
    • Job ( Unity's Job System is "async" )
    • Timeline ( Another thread timeline )
    • Path ( Same as timeline, but shorter )
    • Execution ( What a CPU thread does )
    • Process ( Same as execution, but shorter )
    • Operation ( I think Unity has a class called AsyncOperation for the asychrony of SceneManager )
    • Objective ( Similiar to Operation )
    • Parallel ( C#'s threaded model )
    • Stereo ( Instead of a mono threaded model )
    • Independent ( A thread that doesn't rely on timeDelta or Object destruction, but is independent )
    • Free ( Same as independent, but shorter )
    • Unbound ( Similiar to independent, but shorter )
    • Thread ( No need for explanation... right? Right?? )
    • Pause ( As it can be awaited or the thread delayed )
    • Seperation ( Seperated from the main thread )

    Let's hope we can find a good name together that is ( hopefully ) rather short... ;)
     
    Last edited: Oct 10, 2022
    CaseyHofland likes this.
  30. grizzly

    grizzly

    Joined:
    Dec 5, 2012
    Posts:
    356
    A compromise; AsyncRoutine
     
  31. SonicBloomEric

    SonicBloomEric

    Joined:
    Sep 11, 2014
    Posts:
    1,081
    This. A thousand times this. Coroutines in Unity are a very specific implementation of async. They have their own manual page that describes what they are and how to use them.

    "Coroutine" means something extremely specific within Unity and yet you are attempting to widen its meaning with the "AwaitableCoroutine" term.

    DO NOT DO THIS.

    Sticking "Coroutine" in the name here will drive no end of confusion for your users. The very first thing that you'll have to add to any documentation on the subject is "Despite the name, AwaitableCoroutine is only vaguely related to Unity's Coroutine implementation" and then you'll have to dig into what makes them different.

    Please nip this silliness in the bud.

    Any of those are better than the existing term. To restate:
    • UnityAwaitable
    • UnityFuture
    • UnityPromise
    are ALL dramatically preferable to "AwaitableCoroutine". Personally (and without any solid understanding of how they're used yet), I think the best of the options is the first. Using the terms "Future" or "Promise" may also feel misleading to folks coming from different language backgrounds (Python/JavaScript/etc.). If you're making something Unity-specific and this something boils down to "can be awaited" then "UnityAwaitable" sounds like an extremely reasonable name.

    Even this is preferable to AwaitableCoroutine or AsyncCoroutine.

    Excise the term "Coroutine" from this as fast as possible. You will do all of us a disservice by leaving it in.
     
  32. TangerineDev

    TangerineDev

    Joined:
    Sep 28, 2020
    Posts:
    122
    Honestly, I agree!

    By using the term Coroutine you are defining smth. that was already doing a task synchronously, but has another Routine which will occur later.
    E.g. Cooking an Egg leaving it, to go cut some tomatoes, but if one side of the eggs are finished you return to the eggs and leave the tomatoes.

    So a proper new name kind of makes more sense especially when Async and Coroutines are 2 totally different ways to delay execution.
     
  33. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,194
    Gonna second what's been said above here.

    I have on notifications for this thread, but I don't really care much about async/await, so I kinda skimmed/skipped all of the posts about this feature.

    I was totally assuming that it was some kind of native interoperability between async/await and Coroutine. So, yeah, don't name it that. At least, save the community from having to spend one million hours and way too much pain teaching people the difference.
     
    TangerineDev likes this.
  34. TangerineDev

    TangerineDev

    Joined:
    Sep 28, 2020
    Posts:
    122
    To this I disagree though!
    First of all why do we need the Unity name in this implementation? Aren’t namespaces designed to identify from which company/group a class is coming from? Also we have Coroutines not UnityCoroutines!

    Also
    Code (CSharp):
    1. await new Awaitable()
    seems super silly imo…

    Like if we’re using an obviously asynchronous method then do we really need to specify that it is awaitable?
     
  35. SonicBloomEric

    SonicBloomEric

    Joined:
    Sep 11, 2014
    Posts:
    1,081
    It sounds like you don't "disagree" with those name suggestions so much as you take issue with the names in general, yeah?

    I see your concerns/points but I will suggest that there's precedence in UnityEvent. I'm not trying to suggest that "UnityEvent" is some sort of perfect name, but it does make the point that it's a Unity-specific event implementation. The purpose of "Unity" in that name is to disambiguate from another standard implementation (as well as improve searchability with tools like grep).

    In this case, you could argue that "C# does not define Promise or Future". To that I would suggest "well, not yet". Those concepts are pretty common across multiple languages and being able to search the web for "unityfuture" would be preferable to "unity future".

    Even if Unity decided to use something like UnityEngine.UnityFuture as the type name, you could locally rename it with something like:
    Code (CSharp):
    1. using FutureInt = UnityEngine.UnityFuture<int>;
    if you're truly afraid of typing out the "Unity" prefix the handful of times you'd need this.

    My point is that it I would basically prefer UnitySomething to anything with the term "coroutine" in it.

    I guess that's fair? I'm not especially partial to any of those names myself. I just really, really hope that "coroutine" is removed from whatever they go with because that is straight-up garbage.
     
    Last edited: Oct 10, 2022
    TangerineDev and Anthiese like this.
  36. CaseyHofland

    CaseyHofland

    Joined:
    Mar 18, 2016
    Posts:
    548
    I don't know if that's true, because Coroutine is still the thing that it is in the background, and including "Coroutine" in the name specifies that. Even worse, because I'm a sick broken man, after mulling it over I'm now back on
    AsyncCoroutine
    as it would be similar to how they added
    IAsyncEnumerable
    to C#. But then
    AsyncRoutine
    might be better because a Coroutine is redundant if it's already async, but then again if it wouldn't be async it would still be a Coroutine so maybe the name is valid... oh brother

    But if not... then I think
    UnityTask
    would be the best fit. Purely going by the "don't overthink it"-principle, that's the name everyone started suggesting before there was even discussion about it, so it seems to me that
    UnityTask
    was already in peoples minds before you even explained what any of it did. That's no silver bullet, but it matters. As well:
    I could get behind the logic of "yeah it's a Task but specifically implemented with Unity in mind, hence UnityTask", and that the "Unity implementation part" may be Coroutines is neither here nor there.

    Truly, just make
    NextFrame
    and friends Tasks so we can sidestep this naming-business altogether XD T_T
     
    Last edited: Oct 11, 2022
    JesOb likes this.
  37. TieSKey

    TieSKey

    Joined:
    Apr 14, 2011
    Posts:
    219
    Mmmmmm I think this naming thing is a little offtopic, but not unproductive nor undesirable in itself. It might be useful to move to a different thread?

    As for the naming thing in particular, I'm seeing a lot of suggestions that despite the reasoning, end up with very non descriptive names. Async in unity is coroutines, is the only thing we ever had from the engine side, having a "specialized" coroutine that have most of the same semantics: cancels on destruction, can wait for frames/unity events, returns to the main thread and only a few differences: has a typed return value, can be awaited with the async keyword, be called "AwaitableCoroutine" is quite descriptive. It tells u it has almost the same semantics but that u can also await on it. (u know, as any specialization class is usually named in OOP...)

    For some additional context:
    are "classic" coroutines being deprecated?
    is a AwaitableCoroutine a Coroutine? (as in, do they share an ancestor? IEnumerator?).
    Do we have utility methods to cancel AwaitableCoroutines without directly interacting with the cancellation token?
    The underlying question is, how similar will u make to use one or the other?
     
    Nad_B, Huszky, NotSlot and 1 other person like this.
  38. SonicBloomEric

    SonicBloomEric

    Joined:
    Sep 11, 2014
    Posts:
    1,081
    Is that the case, though? @simon-ferquel-unity explained it as supporting:

    You're suggesting that this is all a wrapper for an internal use of Unity's standard Coroutines?
     
  39. TangerineDev

    TangerineDev

    Joined:
    Sep 28, 2020
    Posts:
    122
    I don't think they will deprecate any of this as Coroutine is seriously another workflow in of its own...

    The idea of coroutine is to not bother with the execution of another thread which is why we don't have CancellationTokens there.

    I still think though, that the Unity API should slowly become deprecated and be replaced with async methods!



    Task was definitely the first thing people thought of and would be inline with the C# .NET Library and all that shazam.
    But I think Unity has a problem of copyright... I'm not a lawyer myself, but I don't know if it is legal to call it UnityTask as UniTask exists and we only added 2 letters... :(

    As we discussed UnityTask might just be the most comprehensable naming for this feature, but legality wise... hmmm..
     
    JesOb likes this.
  40. runner78

    runner78

    Joined:
    Mar 14, 2015
    Posts:
    760
    Not really, because many async/await totorials/workshops/courses keep saying async != mutlithreading. For example, the await for external resources such as web requests, IO, etc., run async, but on the same thread.

    Therefore, for me, UnityTask would be the best name, since it would be consistent with the C# names. A Task can also be executed on the same thread Task != Thread.
     
  41. Qbit86

    Qbit86

    Joined:
    Sep 2, 2013
    Posts:
    487
  42. Huszky

    Huszky

    Joined:
    Mar 25, 2018
    Posts:
    106
    Or since it is still a Task call it something Task like?
     
    Kamyker likes this.
  43. simon-ferquel-unity

    simon-ferquel-unity

    Unity Technologies

    Joined:
    Apr 1, 2021
    Posts:
    65
    I've been through all the naming comments here and have seen interesting things:
    - Coroutine in the name is quite bad. It make it feels like a Unity Coroutine 2.0 which it is not. It is much more abstract than that and cover things like events, async operations etc.
    - Task is not that confusing to most users, as they already have gone through the "Task" mess in vanilla .net.

    We'll run trough those arguments in a meeting, try to pick a better name based on the suggestions here. Thanks!
     
  44. Laicasaane

    Laicasaane

    Joined:
    Apr 15, 2015
    Posts:
    288
    If *Task is off-limits then I will go with AsyncRoutine. Since according to all the documentation I've read, it's no different from "coroutine".

    However, the Unity documentation said: "In Unity, a coroutine is a method that can pause execution and return control to Unity but then continue where it left off on the following frame."

    Can AwaitableCoroutine pause execution then continue where it left off too?
     
  45. MiTschMR

    MiTschMR

    Joined:
    Aug 28, 2018
    Posts:
    358
    Instead of having async twice, why not use AwaitableRoutine?
     
  46. Kamyker

    Kamyker

    Joined:
    May 14, 2013
    Posts:
    1,084
    +1 for UnityTask or UTask (I like shorter one more).

    It's better to inline with .NET naming. As a bonus it's similar to Unreal's AsyncTask.

    Is UnityTask a struct? If not and in the future UnityValueTask may be added then shorter names are simpler UTask, UValueTask.

    Waiting for EndOfFrame sounds like a task.
     
    Last edited: Oct 11, 2022
  47. TangerineDev

    TangerineDev

    Joined:
    Sep 28, 2020
    Posts:
    122
    Because we will have await twice if we await it...

    await new AwaitableRoutine


    ...also we already decided that Routine or Coroutine is a bad idea. Read this page if you wanna know why.
     
  48. Qbit86

    Qbit86

    Joined:
    Sep 2, 2013
    Posts:
    487
    “UTask” is explicitly against .NET naming [1][2]:

    ❌ DO NOT use abbreviations or contractions as part of identifier names.
    ❌ DO NOT use any acronyms that are not widely accepted, and even if they are, only when necessary.
    ❌ DO NOT give class names a prefix (e.g., "C").

    “UnityTask” — this is also uncommon in standard libraries to have types like MicrosoftSomething or XamarinSomething.
    The brand name “Unity” is a part of the namespace; there is no point in duplicating it in the name of a type: `UnityEngine.UnityTask`.

    [1] https://learn.microsoft.com/en-us/dotnet/standard/design-guidelines/general-naming-conventions
    [2] https://learn.microsoft.com/en-us/d...lines/names-of-classes-structs-and-interfaces
     
  49. TangerineDev

    TangerineDev

    Joined:
    Sep 28, 2020
    Posts:
    122
    yes.

    The Unity API doesn't have anything that is prefixed with just a U ( correct me if I'm wrong ), so for concistency's sake let's agree on UnityTask!
     
  50. TangerineDev

    TangerineDev

    Joined:
    Sep 28, 2020
    Posts:
    122
    Which is what I said, but UnityActions, UnityEvents, etc. exist as some people stated in this thread, so naming it UnityTask does make sense.

    Also Unity always adds the Unity prefix to classes if they already exist in C#.
    Actions are a part of C# as well as Events :D