Search Unity

How do you ensure that a JobComponentSystem gets executed before a ComponentSystem?

Discussion in 'Entity Component System' started by davenirline, Jul 5, 2018.

  1. davenirline

    davenirline

    Joined:
    Jul 7, 2010
    Posts:
    986
    It seems that a JobComponentSystem doesn't execute right away. I tried using UpdateBefore but it doesn't work.

    Code (csharp):
    1.  
    2. [UpdateBefore(typeof(SystemB))]
    3. class SystemA : JobComponentSystem {
    4.     ...
    5. }
    6.  
    7. class SystemB : ComponentSystem {
    8.     protected override void OnUpdate() {
    9.         // While debugging, I saw that the data was not yet updated in SystemA
    10.     }
    11. }
    12.  
     
  2. 5argon

    5argon

    Joined:
    Jun 10, 2013
    Posts:
    1,555
    Maybe the injects in your SystemA was not satisfied at that frame and it skips the update?
     
  3. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,685
    Because systems without injection - disabled. Systems are automatically disabled when all ComponentGroups have zero entities. [AlwaysUpdateSystem] can be used to always force update a system.
     
  4. 5argon

    5argon

    Joined:
    Jun 10, 2013
    Posts:
    1,555
    Actually system with no injection equals to AlwaysUpdateSystem! (excerpt from ComponentSystemBase)

    But with one or more injection defined, if it has zero entity coming then it is automatically disabled. This is correct.

    Code (CSharp):
    1.         public bool ShouldRunSystem()
    2.         {
    3.             if (m_AlwaysUpdateSystem)
    4.                 return true;
    5.  
    6.             var length = m_ComponentGroups?.Length ?? 0;
    7.  
    8.             if (length == 0)
    9.                 return true;
    10.  
    11.             // If all the groups are empty, skip it.
    12.             // (There’s no way to know what they key value is without other markup)
    13.             for (int i = 0;i != length;i++)
    14.             {
    15.                 if (!m_ComponentGroups[i].IsEmptyIgnoreFilter)
    16.                     return true;
    17.             }
    18.  
    19.             return false;
    20.         }

    Code (CSharp):
    1.         internal sealed override void InternalUpdate()
    2.         {
    3.             if (Enabled && ShouldRunSystem()) { ...
     
    eizenhorn likes this.
  5. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,685
    Yes, I'm sorry, sleepwalker incorrectly wrote, I meant exactly zero entities, the system without injecting always work of course.
     
    5argon likes this.
  6. 5argon

    5argon

    Joined:
    Jun 10, 2013
    Posts:
    1,555
    Ok English is difficult.. op if you are confused my "injection" meant the presence of `[Inject]` tag or any first time use of a unique `GetComponentGroup` but @eizenhorn 's "injection" meant the amount of entities that is coming in as a result of those injection.

    - Injection defined : 0 -> Always update
    - Injection defined : 1+ / Entities injected : 0 -> Does not update
    - Injection defined : 1+ / Entities injected : 1+ -> Updates
    - Injection defined : 1+ / Entities injected : 0 / [AlwaysUpdateSystem] -> Always update

    So it might be that in your ... it decided that the system should not update.
     
  7. davenirline

    davenirline

    Joined:
    Jul 7, 2010
    Posts:
    986
    I'll see if there were no entities injected to SystemA. I'm transforming a ComponentSystem into a JobComponentSystem. The ComponentSystem version works and I didn't change the injected data.
     
  8. davenirline

    davenirline

    Joined:
    Jul 7, 2010
    Posts:
    986
    It's working now. The job system just had an error. Thus, I don't see any updates in SystemB.