Search Unity

NativeArray Change Type

Discussion in 'Entity Component System' started by Bodyclock, May 23, 2020.

  1. Bodyclock

    Bodyclock

    Joined:
    May 8, 2018
    Posts:
    172
    Hi, I have a NativeArray of double3's that I want to convert to float3's. I've played around with ReInterpret (I can get a NativeArray of doubles for what it's worth) and also NativeArray<T>.Copy but no success. I know I can do this with Array.ConvertAll but I have to come out of the NativeArray and I'm trying to do as much as I can without converting.
    Is looping through the best option? There are potentially a million or so elements. Does anyone have any pointers. Thanks.
     
  2. RecursiveEclipse

    RecursiveEclipse

    Joined:
    Sep 6, 2018
    Posts:
    298
    Code (CSharp):
    1. NativeArray<double3> a = new NativeArray<double3>(...);
    2. NativeArray<float3> b = a.Reinterpret<float3>();
    Is this what you need?
     
  3. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,759
    That's not going to work, float/double are not the same size

    There might be some neat data hack I don't know of, but it really shouldn't take that long to convert in a IJobFor
     
  4. Bodyclock

    Bodyclock

    Joined:
    May 8, 2018
    Posts:
    172
    Thanks for the replies. As there's nothing obvious I think I'm just going to create a NativeArray of floats and populate it in the same Job as the doubles.