Search Unity

Allow overriding engine system update timing when subclassing

Discussion in 'Entity Component System' started by 5argon, Mar 4, 2019.

  1. 5argon

    5argon

    Joined:
    Jun 10, 2013
    Posts:
    1,555
    Code (CSharp):
    1.  
    2. [UpdateBefore(typeof(PreLateUpdate))]
    3. public class SA : ComponentSystem
    4. {
    5.     protected override void OnUpdate()
    6.     {
    7.  
    8.     }
    9. }
    This code results in SA automatically added to the World updating in PreLateUpdate.

    Code (CSharp):
    1.  
    2. public class SA2 : SA
    3. {
    4.     protected override void OnUpdate()
    5.     {
    6.    
    7.     }
    8. }
    9.  
    10. [UpdateBefore(typeof(PreLateUpdate))]
    11. public class SA : ComponentSystem
    12. {
    13.     protected override void OnUpdate()
    14.     {
    15.    
    16.     }
    17. }
    This code results in SA2 automatically added to the World, instead of SA since any class that got inherited seems to be excluded (so did any abstract system class and generic system class). SA2 is in PreLateUpdate. It inherits update timing.

    Code (CSharp):
    1.  
    2. [UpdateBefore(typeof(PostLateUpdate))]
    3. public class SA2 : SA
    4. {
    5.     protected override void OnUpdate()
    6.     {
    7.  
    8.     }
    9. }
    10.  
    11. [UpdateBefore(typeof(PreLateUpdate))]
    12. public class SA : ComponentSystem
    13. {
    14.     protected override void OnUpdate()
    15.     {
    16.  
    17.     }
    18. }
    This code throws "over constrained" error since it seems to understand that I want it to be in 2 places of system phase at once. However my intention is to replace the constraint. My request is that could you make it so the inheriting system only goes according to its engine system attribute (if any) and not looking to the base class? Also could it be useful if we have an attribute that somehow removes the base class's engine system constraint?

    Imagine that SA comes from other programmer with the attribute and I can't remove it, but I want to move my inherited system to other place.
     
    JesOb likes this.