Search Unity

  1. If you have experience with import & exporting custom (.unitypackage) packages, please help complete a survey (open until May 15, 2024).
    Dismiss Notice
  2. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice

[Solved] How to SetFixedArray, back to entity?

Discussion in 'Entity Component System' started by Antypodish, Aug 5, 2018.

  1. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,790
    HI,

    Well, of coruse there is no such thing as SetFixedArray.
    In contrast, you can get

    Code (CSharp):
    1. MyComponent data = EntityManager.GetComponentData <MyComponent> ( entity ) ;
    and set

    Code (CSharp):
    1. EntityManager.SetComponentData ( entity, data ) ;

    I can of course fetch fixed array

    Code (CSharp):
    1. EntityManager.GetFixedArray <MyStruct> ( entity ) ;
    As an example into native array

    Code (CSharp):
    1. Unity.Collections.NativeArray <MyStruct> a_myStructs = entityManager.GetFixedArray <MyStruct> ( entity ) ;
    Then after manipulating with array,

    how do I set it back to entity?
    Since there is no SetFixedArray.
     
  2. dartriminis

    dartriminis

    Joined:
    Feb 3, 2017
    Posts:
    157
    You can only get a fixed array. Once you have the fixed array, you can get and set elements just as you would a native array. IIRC, getting a fixed array doesn't get a copy of the data, so any change you make is permanent.
     
  3. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,790
    This was my thought too that data is accessed and set by reference, rather just copy data.
    But for some reason, when I get element with index from fixed array and set value, then get the array again, to check if value has been set and stored, debugger says it is old value instead.

    So it a bit troubling me.

    For example,
    Code (CSharp):
    1. a_pointOctreeNodeChildren = entityManager.GetFixedArray <PointOctreeNodeChild> ( entity ) ;
    2. pointOctreeNodeChild = a_pointOctreeNodeChildren [0] ;
    3. pointOctreeNodeChild.centerOffset = new float3 (1,1,2) ;
    4.  
    5. // test check, just after set float3
    6. a_pointOctreeNodeChildren = entityManager.GetFixedArray <PointOctreeNodeChild> ( entity ) ;
    7. pointOctreeNodeChild.centerOffset = a_pointOctreeNodeChildren [0] // test check ;
    test check pointOctreeNodeChild.centerOffset is not the same, when new float3 has been set.

    I may missing something
     
  4. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,790
    Ok I have figured out. Still thinking in OOP categories, that is my problem ^.^
    I need think more abut data, rather references.

    Instead
    Code (CSharp):
    1. a_pointOctreeNodeChildren = entityManager.GetFixedArray <PointOctreeNodeChild> ( entity ) ;
    2. pointOctreeNodeChild = a_pointOctreeNodeChildren [0] ;
    3. pointOctreeNodeChild.centerOffset = new float3 (1,1,2) ;
    I need
    Code (CSharp):
    1. a_pointOctreeNodeChildren = entityManager.GetFixedArray <PointOctreeNodeChild> ( entity ) ;
    2. pointOctreeNodeChild = a_pointOctreeNodeChildren [0] ;
    3. pointOctreeNodeChild.centerOffset = new float3 (1,1,2) ;
    4. a_pointOctreeNodeChildren [0] = pointOctreeNodeChild ;
    Which basically adds extra line
    Code (CSharp):
    1. a_pointOctreeNodeChildren [0] = pointOctreeNodeChild ;
     
    pahe likes this.