Generic Components Not Recognized in Entity Queries – Registration Fails Despite All Workarounds

Hello everyone,

I’ve been experiencing a persistent issue with generic components in Unity’s ECS/NetCode. I’m attempting to use generic RPC components (specifically, using RpcCommandRequest<SyncDataRpc, SyncDataRpc>) in an entity query, but Unity’s type manager complains that the type is unknown at compile time.

Exception:

ArgumentException: Unknown Type:`Unity.NetCode.RpcCommandRequest`2[SyncDataRpc,SyncDataRpcc]` All ComponentType must be known at compile time. For generic components, each concrete type must be registered with [RegisterGenericComponentType].

RPC Type:

[BurstCompile]
public struct SyncDataRpc: IComponentData, IRpcCommandSerializer<SyncDataRpc>
{
    public int Data;
    // Serialize, Deserialize, CompileExecute implementations...
}

Generic Registration:

using Unity.Entities;
using Unity.NetCode;

[assembly: RegisterGenericComponentType(typeof(RpcCommandRequest<SyncDataRpc, SyncDataRpc>))]

Query:

var builder = new EntityQueryBuilder(Allocator.Temp)
    .WithAny<RpcCommandRequest<SyncDataRpc, SyncDataRpc>>();
m_RPCsQuery = state.GetEntityQuery(builder);

Has anyone encountered similar issues with generic component registration and entity queries? Are there additional workarounds or known package bugs that might be causing this behavior? Any help or insight would be greatly appreciated.

Thanks in advance!

The RpcCommandRequest struct is not a IComponentData (or a IBufferElementData) and cannot be used as part of an EntityQuery. You can refer to this page in the documentation on how to use custom serializers for Rpc’s, including how to send them.

1 Like

Appreciate the insight! I see now why RpcCommandRequest can’t be used in an EntityQuery. I’ll look into custom serializers for RPCs as suggested. Thanks again!