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

Bug Generic SystempAPI.Query<T> codegen error

Discussion in 'Entity Component System' started by kirkgamesllc, Sep 6, 2023.

  1. kirkgamesllc

    kirkgamesllc

    Joined:
    Jan 7, 2023
    Posts:
    6
    Code (CSharp):
    1.  
    2. private void SendSpawnRequest<T>(ref SystemState state, ref Singleton singleton) where T : IQueryTypeParameter
    3.     {
    4.         EntityCommandBuffer ecb = SystemAPI.GetSingletonRW<BeginSimulationEntityCommandBufferSystem.Singleton>().ValueRW.CreateCommandBuffer(state.WorldUnmanaged);
    5.  
    6.         foreach ((T request, Entity entity) in SystemAPI.Query<T>().WithNone<SendRpcCommandRequest>().WithEntityAccess())
    7.         {
    8.             // final validation check for client connection to server
    9.             if (SystemAPI.HasSingleton<NetworkId>())
    10.             {
    11.                 // Send T spawn request to the server
    12.                 ecb.AddComponent(entity, new SendRpcCommandRequest());
    13.             }
    14.         }
    15.     }
    16.  
    17.     public struct SpectreSpawnRequest : IRpcCommand, IQueryTypeParameter
    18.     {
    19.         public FixedString128Bytes PlayerName;
    20.     }
    21.  
    22.     public struct ThirdPersonSpawnRequest : IRpcCommand, IQueryTypeParameter
    23.     {
    24.         public FixedString128Bytes PlayerName;
    25.         public float Delay;
    26.     }
    27.  
    28.  
    I have a several of these Send*SpawnRequest methods and I'm attempting to make a generic, but the codegen is throwing an error.
    Am I doing something wrong?

    `
    SGICE002: This error indicates a bug in the DOTS source generators. We'd appreciate a bug report (Help -> Report a Bug...). Thanks! Error message: 'System.InvalidCastException: Unable to cast object of type 'Microsoft.CodeAnalysis.CSharp.Symbols.PublicModel.TypeParameterSymbol' to type 'Microsoft.CodeAnalysis.INamedTypeSymbol'. |--| at Unity.Entities.SourceGen.SystemGenerator.SystemAPI.Query.IdiomaticCSharpForEachDescription.<TryGetQueryDatas>g__TryGetIdiomaticCSharpForEachQueryType|73_0(ITypeSymbol typeSymbol, Location errorLocation) |--| at Unity.Entities.SourceGen.SystemGenerator.SystemAPI.Query.IdiomaticCSharpForEachDescription.TryGetQueryDatas(ICollection`1& queryTypes) |--| at Unity.Entities.SourceGen.SystemGenerator.SystemAPI.Query.IdiomaticCSharpForEachDescription..ctor(SystemDescription systemDescription, QueryCandidate queryCandidate, Int32 numForEachsPreviouslySeenInSystem) |--| at Unity.Entities.SourceGen.SystemGenerator.SystemAPI.Query.IdiomaticCSharpForEachModule.RegisterChangesInSystem(SystemDescription systemDescription) |--| at Unity.Entities.SourceGen.SystemGenerator.SystemGenerator.Execute(GeneratorExecutionContext context)'
     
  2. Laicasaane

    Laicasaane

    Joined:
    Apr 15, 2015
    Posts:
    288
    You have to wait until they make SystemAPI source generetor properly supports generic. Until then, stay away from this kind of generic.

    One alternative solution is building the query manually.

    On the other hand, you should correct the constraint on T
    where T : unmanaged, IComponentData, IQueryTypeParameter
     
  3. kirkgamesllc

    kirkgamesllc

    Joined:
    Jan 7, 2023
    Posts:
    6
    Bummer about the waiting game.

    Query only has the IQueryTypeParameter constraint, why does it need the others?
    public static QueryEnumerable<T1> Query<T1> () where T1 : IQueryTypeParameterr
     
  4. Laicasaane

    Laicasaane

    Joined:
    Apr 15, 2015
    Posts:
    288
    Since I tell you to not do what you're trying to do, my addition on T constraint is for other purpose: the alternative solution.