Search Unity

Strange bug in SetFilterChanged?

Discussion in 'Entity Component System' started by echeg, Mar 31, 2019.

  1. echeg

    echeg

    Joined:
    Aug 1, 2012
    Posts:
    90
    I use SetFilterChanged in many systems and I have never experienced a space before.
    But today I am faced with very strange behavior. When I remove component A(EnemyTicksToApplyAction) from Entity SetFilterChanged triggered on component B(EnemyInAction)

    I Have two systems (I disable all other systems from editor)

    First system remove component EnemyTicksToApplyAction when tick count = 0
    Code (CSharp):
    1.     [UpdateAfter(typeof(EnemyActionMeleAttackSystem))]
    2.     public class EnemyActionCountdownTicksSystem : ComponentSystem
    3.     {
    4.         private ComponentGroup _notifyGroup;
    5.        
    6.         protected override void OnCreateManager()
    7.         {
    8.             _notifyGroup = GetComponentGroup(
    9.                 typeof(EnemyTicksToApplyAction));      
    10.         }
    11.        
    12.         protected override void OnUpdate()
    13.         {
    14.             if (_notifyGroup.CalculateLength() == 0) return;
    15.  
    16.             var data = _notifyGroup.ToEntityArray(Allocator.TempJob);
    17.             foreach (var e in data)
    18.             {
    19.                 var ticks = EntityManager.GetComponentData<EnemyTicksToApplyAction>(e);
    20.                 var newtick = ticks.Value - 1;
    21.                 EntityManager.SetComponentData(e, new EnemyTicksToApplyAction(newtick));
    22.                
    23.                
    24.                 if (newtick == 0)
    25.                 {
    26.                     Debug.Log(newtick + " " + ticks.Value + " " + e);  
    27.                     PostUpdateCommands.RemoveComponent<EnemyTicksToApplyAction>(e);
    28.                 }
    29.             }
    30.             data.Dispose();
    31.  
    32.         }
    33.     }
    34.  
    35. public struct EnemyTicksToApplyAction : IComponentData
    36. {
    37.     public int Value;
    38.  
    39.     public EnemyTicksToApplyAction(int ticks)
    40.     {
    41.         Value = ticks;
    42.     }
    43. }
    44. public struct EnemyInAction : IComponentData
    45. {
    46. }
    47.  


    Second system with SetFilterChanged

    Code (CSharp):
    1. public class EnemyActionMeleAttackSystem : ComponentSystem
    2.     {
    3.         private ComponentGroup _notifyGroup;
    4.         private EntityArchetype _blockChangePhase;
    5.         protected override void OnCreateManager()
    6.         {
    7.             _notifyGroup = GetComponentGroup(
    8.                 ComponentType.ReadOnly<EnemyInAction>());  
    9.             _notifyGroup.SetFilterChanged(ComponentType.ReadOnly<EnemyInAction>());
    10.              
    11.             _blockChangePhase = EntityManager.CreateArchetype(
    12.                 typeof(BlockChangePhase),
    13.                 typeof(BlockChangePhaseTicks)
    14.             );
    15.         }
    16.        
    17.         protected override void OnUpdate()
    18.         {
    19.             if (_notifyGroup.CalculateLength() == 0) return;
    20.            
    21.             var enemiesAction = _notifyGroup.ToEntityArray(Allocator.TempJob);
    22.  
    23.             Debug.Log("EnemyActionMeleAttackSystem " + enemiesAction.Length);
    24.             for (var index = 0; index < enemiesAction.Length; index++)
    25.             {
    26.                 var entity = enemiesAction[index];
    27.                 var gp = EntityManager.GetComponentData<EnemyGridPos>(entity);
    28.                 if (gp.Value.y == 0)
    29.                 {
    30.                     var ed = EntityManager.GetComponentData<EnemyMeleAttack>(entity);
    31.                     maxAttackTime = math.max(ed.AttackTicksFull, maxAttackTime);
    32.                     EntityManager.AddComponentData(entity, new EnemyTicksToApplyAction(ed.AttackTicksToDamage));
    33.                 }
    34.             }
    35.  
    36.             enemiesAction.Dispose();
    37.         }
    38.     }
    Problem:
    When call "PostUpdateCommands.RemoveComponent<EnemyTicksToApplyAction>(e); " on one Entity (Index 23 version 1)
    When _notifyGroup.SetFilterChanged(ComponentType.ReadOnly<EnemyInAction>()); triggered on all Entitys with EnemyInAction.



    All other systems disabled... _notifyGroup.SetFilterChanged stop triggered if I disable
    EnemyActionCountdownTicksSystem
     
  2. echeg

    echeg

    Joined:
    Aug 1, 2012
    Posts:
    90
    Remove or AddComponent triggered all "SetFilterChanged" associated with entity??