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

Bug INativeList dose not have Add/Remove functions

Discussion in 'Entity Component System' started by Lieene-Guo, Oct 12, 2020.

  1. Lieene-Guo

    Lieene-Guo

    Joined:
    Aug 20, 2013
    Posts:
    547
    I am using a generic Function that takes DynamicBuffer or NativeList as input. So I need to use INativeList.
    But there are not Add/Remove relative API on INativeList.
    Currently, I'm building Extension functions to implement Add/Remove on INativeList.
    Hope API can be added.
    most importantly: Add, RemoveAt, RemoveAtSwapBack.
    Also others like AddRange, RemoveRange...
     
    Last edited: Oct 12, 2020
    l33t_P4j33t and bartofzo like this.
  2. bartofzo

    bartofzo

    Joined:
    Mar 16, 2017
    Posts:
    150
  3. l33t_P4j33t

    l33t_P4j33t

    Joined:
    Jul 29, 2019
    Posts:
    232
    same, posted about this some time ago as well
     
  4. bartofzo

    bartofzo

    Joined:
    Mar 16, 2017
    Posts:
    150
    I guess it's possible to create generic code for Add because INativeList.Length has a setter, but there's no way to do AddRange in an optimized way.
    It would also be great to be able to create a NativeSlice from INativeList. If possible...
     
  5. julian-moschuering

    julian-moschuering

    Joined:
    Apr 15, 2014
    Posts:
    529
    As NativeList has an implicit cast to NativeArray you can simply do
    Code (CSharp):
    1. new NativeSlice<int>(list, 0, 10);
    2. // or
    3. list.AsArray().Slice(0, 10);
    You can add a
    Slice
    extension to NativeList to get the same syntax as NativeArray.
     
  6. bartofzo

    bartofzo

    Joined:
    Mar 16, 2017
    Posts:
    150
    Yes, but I meant INativeList. So it's possible to use the same code for DynamicBuffer for instance.
     
  7. julian-moschuering

    julian-moschuering

    Joined:
    Apr 15, 2014
    Posts:
    529