Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Feedback Brief new API feedback

Discussion in '2022.2 Beta' started by TheZombieKiller, Apr 2, 2022.

  1. TheZombieKiller

    TheZombieKiller

    Joined:
    Feb 8, 2013
    Posts:
    265
    This is a really quick thread to summarize my thoughts after looking through the changelogs and C# reference source changes related to the newly-released 2022.2 alpha.

    CancellationToken properties
    This is a really nice change, I've wanted something like Application.CancellationToken for quite some time now. I am however concerned about the choice to expose a cancellation token on every single MonoBehaviour. It appears to be lazily-allocated, but that's still a pointer of memory overhead for every single MonoBehaviour instance. Maybe instead it might be better to track these outside of the MonoBehaviour instance and offer a GetOrCreateCancellationToken-like API?

    Access to Mesh.bindposes as NativeArray
    This is also really nice, and will allow me to reduce some allocations. However, Mesh.bindposeCount doesn't appear to be settable, meaning I still need to allocate a dummy managed array to resize the buffer.

    I'd also like to bring up my earlier 2022.1 threading wishlist post, as there still doesn't appear to be a proper API to retrieve the main thread's SynchronizationContext. I've updated that thread to contain a more appropriate API proposal, as the Object.IsAlive method previously suggested there was shown to not be necessary.
     
  2. Xan_9

    Xan_9

    Joined:
    Oct 7, 2020
    Posts:
    31
    Undo System: Added: UndoRedoEvent callback containing undo information added.

    is also a welcome addition when working on editor tools.
     
  3. TJHeuvel-net

    TJHeuvel-net

    Joined:
    Jul 31, 2012
    Posts:
    838
    On CancellationToken, i think the naming is quite confusing. It tells me the type of the property, but not what it does.

    IMO it should convey that it cancels when the object is destroyed, as opposed to Disabled for example. Something like `MonoBehaviour.DestroyedCancellationToken`?
     
  4. Thygrrr

    Thygrrr

    Joined:
    Sep 23, 2013
    Posts:
    700
    That's really useful, I currently use Unitask's hack for a destruction token.
    Is there also a OnDisabled token? That one would be even more valuable than the OnDestroy token for most of my purposes. (assuming I don't want to destroy/recreate modeless UI objects all the time, but rather enable them when needed)
     
    mariandev and Prodigga like this.