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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Resolved Span in Unity's API

Discussion in 'Scripting Dev Blitz Day 2023 - Q&A' started by peturdarri, Feb 23, 2023.

  1. peturdarri

    peturdarri

    Joined:
    Mar 19, 2016
    Posts:
    23
    We've started seeing Unity using Span<T> in new APIs, like this one.

    I'd love to see the same done with existing APIs that now use some combination of managed arrays, List<T>, NativeArray<T> and NativeSlice<T>.

    Microsoft was very diligent about adding support for Span all across the standard .NET libraries; so much so that it feels like it's always been there. That effort was well worth it, in my opinion, as C# developers can confidently use Span in their code without worrying about whether the APIs they need to use will support it (for the most part). I can't say the same for Unity today, which is a shame.
     
  2. xoofx

    xoofx

    Unity Technologies

    Joined:
    Nov 5, 2016
    Posts:
    412
    Completely agreed. We have been code reviewing new code and invite developers at Unity to prefer Span over NativeArray/NativeSlice. It will probably take many years to evolve our code base. Span is a lot more interesting because it allows to safely manipulate data array whether it is managed, on the stack or in native memory.

    If you have a particular API that you are using that doesn't have Span and you would like to use it, I invite you to log an issue and engate with the teams that support this API, and see if they could not introduce new Span versions.

    Gradually, over time, we should hopefully get there. But we gonna need to be patient. :)