Search Unity

[DisableAutoCreation] doesn't work on inherited systems

Discussion in 'Entity Component System' started by Quit, Apr 30, 2020.

  1. Quit

    Quit

    Joined:
    Mar 5, 2013
    Posts:
    63
    [DisableAutoCreation] flag doesn't work on inherited systems. If I want to have loads of systems disabled, I just inherit them from the class with [DisableAutoCreation] attribute. However, it doesn't work, unless I go to the Entities package code and modify these lines myself:

    Code (CSharp):
    1.             var disableTypeAutoCreation = Attribute.IsDefined(type, typeof(DisableAutoCreationAttribute), false);
    2.  
    3.             // these types obviously cannot be instantiated
    4.             if (type.IsAbstract || type.ContainsGenericParameters)
    5.             {
    6.                 if (disableTypeAutoCreation)
    7.                     Debug.LogWarning($"Invalid [DisableAutoCreation] on {type.FullName} (only concrete types can be instantiated)");
    8.  
    9.                 return false;
    10.             }
    into this:

    Code (CSharp):
    1.             var disableTypeAutoCreation = Attribute.IsDefined(type, typeof(DisableAutoCreationAttribute), true);
    2.  
    3.             // these types obviously cannot be instantiated
    4.             if (type.IsAbstract || type.ContainsGenericParameters)
    5.             {
    6.                 //if (disableTypeAutoCreation)
    7.                 //    Debug.LogWarning($"Invalid [DisableAutoCreation] on {type.FullName} (only concrete types can be instantiated)");
    8.  
    9.                 return false;
    10.             }
    Is there any reason why Unity doesn't allow this? Or is there any other way how I can manually initialize the systems myself, without Unity manually forcing me to do this on every single system?

    P.S. I use abstract base class for an attribute, hence I don't need that warning as well. I know it won't get initialized.
     
    florianhanke likes this.
  2. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,759
    You can disable auto creation of all systems in an assembly if you create an AssemblyInfo.cs file with

    Code (CSharp):
    1. using Unity.Entities;
    2.  
    3. [assembly: DisableAutoCreation]
     
  3. Quit

    Quit

    Joined:
    Mar 5, 2013
    Posts:
    63
    Yeah, I guess I could move everything into a different assembly, but then half of my scripts would be in one assembly, if I wanted some to be created automatically, and then the rest in another one - if they were manual.

    Simply allowing to mark any class with that attribute would be much more helpful...