Search Unity

All ComponentType must be known at compile time.

Discussion in 'Entity Component System' started by davenirline, Jul 21, 2019.

  1. davenirline

    davenirline

    Joined:
    Jul 7, 2010
    Posts:
    982
    I'm currently getting this error.

    System.ArgumentException : Unknown Type:`CommonEcs.EcsHashMap`2[System.UInt16,CommonEcs.ByteBool]` All ComponentType must be known at compile time. For generic components, each concrete type must be registered with [RegisterGenericComponentType].

    I've encountered this error before and fixed it by creating an AssemblyInfo.cs file and add [assembly: RegisterGenericComponentType()] calls in it. I applied the same fix here and it no longer works. Now I'm confused how to fix this.

    It's maybe because I'm using it in another environment that the fix didn't work. I'm trying to make my unit tests work so the code is running in test environment. There shouldn't be any difference, but maybe there is.

    Or it could be that AssemblyInfo is placed in the wrong folder. But I've tried everything. Tried it in the testing folder, then in the folder where EcsHashMap resides. Both cases don't work.

    What am I missing?
     
  2. davenirline

    davenirline

    Joined:
    Jul 7, 2010
    Posts:
    982
    Nevermind. Used uint instead of ushort. :)
     
  3. Abbrew

    Abbrew

    Joined:
    Jan 1, 2018
    Posts:
    417
    Could you post the code that was causing the issue? Other people might benefit from it
     
  4. davenirline

    davenirline

    Joined:
    Jul 7, 2010
    Posts:
    982
    Every time you use a generic struct or component like EcsHashMap<K, V>, the editor will throw out that error. The fix is to create a file named AssemblyInfo.cs in the same project/folder where such struct is used with the following content:

    Code (CSharp):
    1. using Unity.Entities;
    2.  
    3. [assembly: RegisterGenericComponentType(typeof(EcsHashMap<ushort, ByteBool>))]
    4. // You can specify more concrete types here
     
  5. spaceemotion

    spaceemotion

    Joined:
    Sep 29, 2015
    Posts:
    95
    @davenirline Thank you for the tip! While I'm no longer getting errors, the inspector is now no longer showing any input fields where I can edit the contents (I am using ComponentDataProxy for this).

    upload_2019-9-15_13-52-36.png

    The EntityDebugger shows the data correctly though (even if the naming is a bit wierd):
    upload_2019-9-15_13-52-21.png

    Is that something you had to fix as well? Any hints would be appreciated :)
     
  6. davenirline

    davenirline

    Joined:
    Jul 7, 2010
    Posts:
    982
    Was it showing before? I don't think fields are automatically rendered when using ComponentDataProxy.
     
  7. spaceemotion

    spaceemotion

    Joined:
    Sep 29, 2015
    Posts:
    95
    Yes, they are. Every other ComponentProxy that I have has a neat little inspector.
     
  8. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,683
    Do you added Serializable?
     
  9. spaceemotion

    spaceemotion

    Joined:
    Sep 29, 2015
    Posts:
    95
    @eizenhorn

    Here's the full source Code that I have and is not working as expected:

    Code (CSharp):
    1. using Unity.Entities;
    2.  
    3. public interface ILight {}
    4.  
    5. [System.Serializable]
    6. public struct ElementData<T> : IComponentData {
    7.     public int units;
    8. }
    9.  
    10. public class LightComponent : ComponentDataProxy<ElementData<ILight>> { }
    plus the AssemblyInfo.cs file:
    Code (CSharp):
    1. [assembly: RegisterGenericComponentType(typeof(ElementData<ILight>))]
    (imports left out)
     
    Last edited: Sep 22, 2019
    andreyakladov likes this.
  10. IliqNikushev

    IliqNikushev

    Joined:
    Feb 1, 2017
    Posts:
    22
    I got this while running this piece of code, where {TYPE} was abstract

    Code (CSharp):
    1.  
    2. public class CustomObjectConversionSystem : GameObjectConversionSystem
    3. {
    4.     protected override void OnUpdate()
    5.     {
    6.         Entities.ForEach(({TYPE} input) =>
    7.         { ... }
    8.    }
    9. }
    10.  
    FIX: do not use the abstract type