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

ArchetypeChunk versions

Discussion in 'Entity Component System' started by Tony_Max, Feb 1, 2019.

  1. Tony_Max

    Tony_Max

    Joined:
    Feb 7, 2017
    Posts:
    349
    I'm totaly confused with ArchetypeChunk versions and logic of DidChange method. Ok before last update (which added new parameter uint version to DidChange method) i thought that way: we have AcrhetypeChunkComponentType, ArchetypeChunkBufferType, etc. structs which used in DidChange method. So to detect changes i saved last AcrhetypeChunkComponentType to use it in DidChange and it worked perfectly. Now with new parameter i use current ArchetypeChunkComponentType and LastSystemVersion as 5argon recomends in the quote below.
    So can someone explain how that works. cause i'm not sure i understand it well
     
  2. 5argon

    5argon

    Joined:
    Jun 10, 2013
    Posts:
    1,555
    Each chunk already have a change version tracked per component of that chunk. Change version is not yet a true/false state but just a running number. To get boolean state we need a reference point. (did change from what?) Which is an another version number.

    DidChange is a method on chunk that means "did this chunk changed relative to some system version number?" System version number is updated to globalVersion+1 before OnUpdate. By using LastSystemVersion you are comparing to the point in time on the previous OnUpdate of this system.

    Long version : https://gametorrahod.com/unity-ecs-...eration-didaddorchange-didchange-221427f5361b
     
  3. Tony_Max

    Tony_Max

    Joined:
    Feb 7, 2017
    Posts:
    349
    I have an strange effect. When i use GetArchetypeChunkBufferType<Guest>(bool) with false (which means that it will be RW) everything goes ok. But when i use it with true (RO) GetArchetypeChunkBufferType<Guest>(bool) returns true every OnUpdate independetly of real changes. What i'm doing wrong or how is this related?
    Code (CSharp):
    1. guestChunkBufferType = EntityManager.GetArchetypeChunkBufferType<Guest>(true);
    2. currAcrhetypeChunk.DidChange(guestChunkBufferType, LastSystemVersion) //returns true every OnUpdate independently of real changes of Guest buffers
    3.  
    4. guestChunkBufferType = EntityManager.GetArchetypeChunkBufferType<Guest>(false);
    5. currAcrhetypeChunk.DidChange(guestChunkBufferType, LastSystemVersion) //returns true only if there are real changes
     
    Last edited: Feb 3, 2019
  4. 5argon

    5argon

    Joined:
    Jun 10, 2013
    Posts:
    1,555
    Where did you get your
    currAcrhetypeChunk
    from? ACCT with
    readOnly: true
    will bump version on the chunk immediately if you use that ACCT to get the chunk.
     
  5. Tony_Max

    Tony_Max

    Joined:
    Feb 7, 2017
    Posts:
    349
    currAcrhetypeChunk
    is an element of
    archetypeChunkArray

    Code (CSharp):
    1. var archetypeChunkArray = EntityManager.CreateArchetypeChunkArray(guestQuery, Allocator.TempJob);
     
  6. Tony_Max

    Tony_Max

    Joined:
    Feb 7, 2017
    Posts:
    349
    ACCT is an abbreviation of access type?
     
  7. 5argon

    5argon

    Joined:
    Jun 10, 2013
    Posts:
    1,555
    ACCT is ArchetypeChunkComponentType. You iterate through archetypeChunkArray to get each currAcrhetypeChunk. Then in each currAcrhetypeChunk you get a chunk of specific type by using ACCT with the method GetNativeArray(ACCT). That's when it updates the version number if ACCT is a readOnly:false. I am suspecting that the code you did not show used GetNativeArray and update the version number before these lines.