Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Resolved "Unknown Type: All ComponentType must be known" in 0.17.0

Discussion in 'Entity Component System' started by SchmidtDavidSimon, May 19, 2021.

  1. SchmidtDavidSimon

    SchmidtDavidSimon

    Joined:
    Sep 7, 2020
    Posts:
    13
    So I'm trying to remove a dynamic buffer component off an entity like so:

    Code (CSharp):
    1.  public class LaneInitialization : SystemBase
    2.     {
    3.         private EndInitializationEntityCommandBufferSystem _endInitializationEcbSystem;
    4.  
    5.         protected override void OnCreate()
    6.         {
    7.             _endInitializationEcbSystem = World.GetOrCreateSystem<EndInitializationEntityCommandBufferSystem>();
    8.         }
    9.  
    10.         private void OnUpdate()
    11.         {
    12.             var ecb = _endInitializationEcbSystem.CreateCommandBuffer().AsParallelWriter();
    13.  
    14.             Entities
    15.                 .WithBurst()
    16.                 .ForEach(
    17.                     (Entity entity, int entityInQueryIndex)
    18.                         =>
    19.                     {
    20.                            //...
    21.                         ecb.RemoveComponent<DynamicBuffer<EntryNode>>(entityInQueryIndex, entity);
    22.                         ecb.RemoveComponent<DynamicBuffer<OnStreetNode>>(entityInQueryIndex, entity);
    23.                         ecb.RemoveComponent<DynamicBuffer<ExitNode>>(entityInQueryIndex, entity);
    24.                     }).ScheduleParallel();
    But I get an error saying:
    Unknown Type:`Unity.Entities.DynamicBuffer`1[Components.EntryNode]` All ComponentType must be known at compile time. For generic components, each concrete type must be registered with [RegisterGenericComponentType].

    I've searched the forum and documentation and tried to register the type in an AssemblyInfo.cs like so:

    [assembly: RegisterGenericComponentType(typeof(DynamicBuffer<EntryNode>))]

    But the error persists. Am I not reading the error correctly? For reference, this is my
    EntryNode

    Code (CSharp):
    1. public struct EntryNode : IBufferElementData
    2.     {
    3.         public static implicit operator Translation(EntryNode e) { return e.Value; }
    4.  
    5.         public static implicit operator EntryNode(Translation e) { return new EntryNode { Value = e }; }
    6.        
    7.         public Translation Value;
    8.     }
     
  2. WAYNGames

    WAYNGames

    Joined:
    Mar 16, 2019
    Posts:
    939
    Try :

    ecb.RemoveComponent<OnStreetNode>(entityInQueryIndex, entity);
    instead of
    ecb.RemoveComponent<DynamicBuffer<OnStreetNode>>(entityInQueryIndex, entity);
     
  3. SchmidtDavidSimon

    SchmidtDavidSimon

    Joined:
    Sep 7, 2020
    Posts:
    13
    Worked like a charm Thanks!

    I do have a general follow-up question.

    If I were to create an
    Entities.Foreach()
    and would want to read data from the whole
    DynamicBuffer<EntryNode>
    would I use
    in EntryNode
    or rather
    in DynamicBuffer<EntryNode>

    In case of the first, how would I access the other EntryNodes in the buffer?
     
  4. WAYNGames

    WAYNGames

    Joined:
    Mar 16, 2019
    Posts:
    939
    Entities.ForEach((DynamicBuffer<EntryNode> node)=>{});

    I believe.
     
    Sky_Higher likes this.
  5. SchmidtDavidSimon

    SchmidtDavidSimon

    Joined:
    Sep 7, 2020
    Posts:
    13
    Thanks very much. I'll close this thread then