Hi all,
I’ve found what looks to be a bug in Unity ECS ISystem source generation when using generic components in an idiomatic foreach.
using MyNamespace;
using Unity.Burst;
using Unity.Entities;
using UnityEngine;
[assembly: RegisterGenericComponentType(typeof(MyGenericComponent<Foo>))]
[assembly: RegisterGenericSystemType(typeof(MyGenericSystem<Foo>))]
namespace MyNamespace
{
public struct Foo
{
public float Bar;
}
public struct MyGenericComponent<T> : IComponentData
{
public T Value;
}
public partial struct MyGenericSystem<T> : ISystem
{
[BurstCompile]
public void OnCreate(ref SystemState state)
{
}
[BurstCompile]
public void OnUpdate(ref SystemState state)
{
foreach (var component in SystemAPI.Query<MyGenericComponent<T>>())
{
Debug.Log($"Hello: {component.Value}");
}
}
[BurstCompile]
public void OnDestroy(ref SystemState state)
{
}
}
}
With this generic component + system code, it generates this __AssignQueries method in the generated system code:
void __AssignQueries(ref global::Unity.Entities.SystemState state)
{
var entityQueryBuilder = new global::Unity.Entities.EntityQueryBuilder(global::Unity.Collections.Allocator.Temp);
__query_2064639144_0 =
entityQueryBuilder
.WithAll<T>()
.Build(ref state);
entityQueryBuilder.Reset();
entityQueryBuilder.Dispose();
}
At runtime, OnCreate, it throws ArgumentException: Unknown Type:MyNamespace.Foo All ComponentType must be known at compile time. For generic components, each concrete type must be registered with [RegisterGenericComponentType]. which makes sense because the source generated code is .WithAll<T> which is wrong. It should be .WithAll<MyGenericComponent<T>>.
Is this a bug in the Unity source generators or am I doing something wrong?