Discovered this while adding tests approving all the components and tags are registered for NativeAOT.
During test verification (case when some components are not registered) I've found that schema.ComponentTypeByType and schema.Components contains expected components while schema.ComponentTypes contains valid number but actually different types of components.
Traced the discrepancy till the line in EntitySchema ctor. It results in adding completely different type instead of passed.
Here the test, but it might not be working in a different environment. In that case try to reorder definitions of CompA..C.
[Fact]
public void Todo()
{
var aot = new NativeAOT();
aot.RegisterComponent<CompC>();
var schema = aot.CreateSchema();
// Assert
var expectedType = typeof(CompC);
// Expected:
Assert.Equal(expectedType, schema.ComponentTypeByType[expectedType].Type);
Assert.Contains(expectedType, schema.Components.ToArray().Select(ct => ct?.Type));
// Expected, but fails:
Assert.Contains(expectedType, schema.ComponentTypes.Select(ct => ct.Type));
// Not expected:
// Assert.Contains(typeof(CompA), schema.ComponentTypes.Select(ct => ct.Type));
// Assert.True(schema.ComponentTypes.HasAny(ComponentTypes.Get<CompA>()));
}
public struct CompA : IComponent;
public struct CompB : IComponent;
public struct CompC : IComponent;
Discovered this while adding tests approving all the components and tags are registered for NativeAOT.
During test verification (case when some components are not registered) I've found that
schema.ComponentTypeByTypeandschema.Componentscontains expected components whileschema.ComponentTypescontains valid number but actually different types of components.Traced the discrepancy till the line in EntitySchema ctor. It results in adding completely different type instead of passed.
Here the test, but it might not be working in a different environment. In that case try to reorder definitions of CompA..C.