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

Feedback Brief new API feedback

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

  1. TheZombieKiller


    Feb 8, 2013
    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


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

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


    Jul 31, 2012
    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`?


    Sep 23, 2013
    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.