Search Unity

SetFilterChanged does not work?

Discussion in 'Entity Component System' started by Sashok9203, Sep 17, 2018.

  1. Sashok9203

    Sashok9203

    Joined:
    Jun 3, 2018
    Posts:
    24
    Hello to everyone. Please explain to me why this code does not work.
    Code (CSharp):
    1. using Unity.Entities;
    2. using UnityEngine;
    3.  
    4.  
    5. public struct ComponentB : IComponentData
    6. {
    7.     public int Value;
    8. }
    9.  
    10. public class TestUserInputSystem : ComponentSystem
    11. {
    12.  
    13.  
    14.     struct DataB
    15.     {
    16.         public ComponentDataArray<ComponentB> dataB;
    17.         public readonly int Length;
    18.         public EntityArray entity;
    19.     }
    20.  
    21.     [Inject] DataB dataB;
    22.     protected override void OnCreateManager()
    23.     {
    24.         Enabled = true;
    25.         EntityManager.CreateEntity(typeof(ComponentB));
    26.         EntityManager.CreateEntity(typeof(ComponentB));
    27.     }
    28.  
    29.     protected override void OnUpdate()
    30.     {
    31.  
    32.         if (Input.GetKeyDown(KeyCode.Alpha5))
    33.         {
    34.             ComponentB temp = dataB.dataB[0];
    35.             if (temp.Value == 1) temp.Value = 0;
    36.             else temp.Value = 1;
    37.             dataB.dataB[0] = temp;
    38.         }
    39.  
    40.     }
    41. }
    42.  
    43.     [UpdateAfter(typeof(TestUserInputSystem))]
    44.     public class ReactiveSystem : ComponentSystem
    45.     {
    46.         ComponentGroup reactiveGroup;
    47.         protected override void OnCreateManager()
    48.         {
    49.             reactiveGroup = GetComponentGroup(typeof(ComponentB));
    50.  
    51.         }
    52.         protected override void OnUpdate()
    53.         {
    54.             reactiveGroup.ResetFilter();
    55.             reactiveGroup.SetFilterChanged(typeof(ComponentB));
    56.             if (reactiveGroup.CalculateLength() != 0)
    57.                 Debug.Log("Chenget: " + reactiveGroup.CalculateLength());
    58.             reactiveGroup.SetFilterChanged(ComponentType.Create<ComponentB>());
    59.             if (reactiveGroup.CalculateLength() != 0)
    60.                 Debug.Log("Additive: " + reactiveGroup.CalculateLength());
    61.             reactiveGroup.SetFilterChanged(ComponentType.Subtractive<ComponentB>());
    62.             if (reactiveGroup.CalculateLength() != 0)
    63.                 Debug.Log("Subtractive: " + reactiveGroup.CalculateLength());
    64.  
    65.         }
    66.     }
    67.  
    After pressing the key , ComponentGroup reacts to the change, but SetFilterChanged does not work, because the result for all filters is the same.
    SetFilterChanged does not work yet, or am I doing something wrong?
     
  2. Sashok9203

    Sashok9203

    Joined:
    Jun 3, 2018
    Posts:
    24
    Maybe someone can give a link to the working code, where it is used SetFilterChanged?
     
  3. Sashok9203

    Sashok9203

    Joined:
    Jun 3, 2018
    Posts:
    24
    I still do not understand, no one knows anything about this, or are they simply ignoring me?
    It seems that the problem exists only for me ....
     
  4. Spy-Shifty

    Spy-Shifty

    Joined:
    May 5, 2011
    Posts:
    546
  5. nttLIVE

    nttLIVE

    Joined:
    Sep 13, 2018
    Posts:
    80
    This.

    But also shouldn't you be using SetFilter and not SetFilterChanged? I'm not sure if GetComponentGroup is what you want to use for your case. You might want to check other ways to inject Components in your System.
     
  6. Sashok9203

    Sashok9203

    Joined:
    Jun 3, 2018
    Posts:
    24
    I need my system to work only with those components that have been changed. Initially I tried to add one more component to the entity when the desired component was changed. And in this way to determine which component was changed. But this method does not work. There are a lot of elements and constantly deleting and adding components is bad for performance.
    What other ways can you identify components that have been changed?
    Tell me, is it better to use EndFrameBuffer for all systems or use a separate Barrier for each system separately?
     
    Last edited: Sep 20, 2018
  7. Spy-Shifty

    Spy-Shifty

    Joined:
    May 5, 2011
    Posts:
    546