Search Unity

RegisterGenericComponentType and inner structs

Discussion in 'Data Oriented Technology Stack' started by Arkuni, Oct 9, 2019.

  1. Arkuni

    Arkuni

    Joined:
    May 30, 2013
    Posts:
    10
    Does anyone know if the following is possible in some way?

    Right now it complains with:

    All ComponentType must be known at compile time. For generic components, each concrete type must be registered with [RegisterGenericComponentType].

    Code (CSharp):
    1. using Unity.Entities;
    2. using Unity.Jobs;
    3. using Unity.Mathematics;
    4.  
    5. [assembly: RegisterGenericComponentType(typeof(GenericSystem<float>))]
    6. [assembly: RegisterGenericComponentType(typeof(GenericSystem<float2>))]
    7. [assembly: RegisterGenericComponentType(typeof(GenericSystem<float3>))]
    8.  
    9. public abstract class GenericSystem<T> : JobComponentSystem
    10. {
    11.     protected override JobHandle OnUpdate(JobHandle inputDeps)
    12.     {
    13.         return inputDeps;
    14.     }
    15.    
    16.     public struct Component : IComponentData
    17.     {
    18.         public T Value;
    19.     }
    20. }
     
  2. M_R

    M_R

    Joined:
    Apr 15, 2015
    Posts:
    485
    maybe with
    Code (CSharp):
    1. [assembly: RegisterGenericComponentType(typeof(GenericSystem<float>.Component))]
    2. /// etc...
     
  3. Arkuni

    Arkuni

    Joined:
    May 30, 2013
    Posts:
    10
    Nope. That is not legal C# code.
     
  4. M_R

    M_R

    Joined:
    Apr 15, 2015
    Posts:
    485
    yes it is. unless you renamed the component class
     
  5. Arkuni

    Arkuni

    Joined:
    May 30, 2013
    Posts:
    10
    I don't get it. What would be the right way to write it?
     
  6. Ziboo

    Ziboo

    Joined:
    Aug 30, 2011
    Posts:
    297
    Maybe ?:
    Code (CSharp):
    1. public abstract class GenericSystem<T> : JobComponentSystem where T: struct, IComponentData