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 Entity Version / LinkedEntityGroup, Version does not get counted up

Discussion in 'Entity Component System' started by Daxten, Aug 16, 2021.

  1. Daxten

    Daxten

    Joined:
    Sep 20, 2013
    Posts:
    30
    I don't have time atm to create a minimal example, but on the latest version I have the following problem:

    Code (CSharp):
    1.  
    2.  
    3.                  var entityGroup = buffer.AddBuffer<LinkedEntityGroup>(worldEntity);
    4.                 // Workaround? First entities version get counted up to 2...
    5.                     var workaroundEntity = buffer.CreateEntity();
    6.                     entityGroup.Add(new LinkedEntityGroup()
    7.                     {
    8.                         Value = workaroundEntity
    9.                     });
    10.  
    11.                     for (int dx = 0; dx < world.width; dx += 1)
    12.                     {
    13.                         for (int dy = -world.depth; dy < world.height; dy += 1)
    14.                         {
    15.                             for (int dz = 0; dz < world.width; dz += 1)
    16.                             {
    17.                                 var chunk = buffer.CreateEntity();
    18.                                 entityGroup.Add(new LinkedEntityGroup()
    19.                                 {
    20.                                     Value = chunk
    21.                                 });
    22.                             }
    23.                         }
    24.                     }
    Later on different frame:
    Code (CSharp):
    1. buffer.DestroyEntity(worldEntity);
    The first entity created in the buffer has its version set to 2.
    all others are set to 1.
    LinkedEntityGroup contains all entities with version 1.

    When destroying the parent, only the entities with version 1 are getting destroyed.

    I actually have no idea how/when the version gets counted up. But since I never do anything with the workaroundEntity it seems like this is a bug.

    might also have to do with the buffer
     
  2. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    3,983
    I'm not sure I understand what you are doing, but I know that the first entity in the LinkedEntityGroup should be worldEntity itself.
     
  3. Daxten

    Daxten

    Joined:
    Sep 20, 2013
    Posts:
    30
    I dont think what you are saying is right, the Buffer is on the worldEntity in this case and the children inside the buffer
     
  4. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    3,983
    Unity's convention is that the first entity in a LinkedEntityGroup is the entity the buffer is attached to, followed by all of that entity's linked children and their children and so on. It is not the most intuitive, but it is what it is.
     
  5. Daxten

    Daxten

    Joined:
    Sep 20, 2013
    Posts:
    30
    Where is that documented, and if that is the case then it is bugged in other ways cause I don't do that and it still works

    I can't find any examples for that
     
  6. Tony_Max

    Tony_Max

    Joined:
    Feb 7, 2017
    Posts:
    334
    it is 100% that LinkedEntityGroup should contain 1st element as entity itself. You can inspect EntityManager.DestroyEntity and it will search for LinkedEntityGroup and if manager will find this buffer then it will iterate through buffer only
     
  7. Daxten

    Daxten

    Joined:
    Sep 20, 2013
    Posts:
    30
    yes you are right :+1 maybe sth for the documentation thanks for the help