Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

NativeArray indexing operator not returning by ref

Discussion in 'Entity Component System' started by sebas77, Aug 14, 2019.

  1. sebas77

    sebas77

    Joined:
    Nov 4, 2011
    Posts:
    1,641
    is there an alternative workaround to this problem? I need to change single fields of the structs held by the NativeArray and I can't do that.
     
  2. sebas77

    sebas77

    Joined:
    Nov 4, 2011
    Posts:
    1,641
    NVM I forgot about the UnsafeUtilityEx in the collection package, however it seems a bit hackish
     
  3. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,753
    Struggling to understand your problem.

    I assume it is

    Array.Value =x // doesn't work

    But the solution has always been

    var element = Array
    element.Value = x
    Array = element
     
  4. sebas77

    sebas77

    Joined:
    Nov 4, 2011
    Posts:
    1,641
    doing what you said could comprise the performance in a cache friendly performance critical scenario.

    more info: Nowadays CPUs can read a continuous block of data up to 64 bytes in one single memory access from the L1 cache (which takes around 4 cycles of clock). If the struct is more than 64 bytes you can have a good hit in performance.
     
  5. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    4,217
    Burst usually optimizes that away and just modifies the array in place.
     
  6. sebas77

    sebas77

    Joined:
    Nov 4, 2011
    Posts:
    1,641
    hmmmmmmm that would make sense although it seems quite an advanced analysis. I'll check it.