SourceGen Bug: SystemAPI.QueryBuilder().WithAllChunkComponent + SystemAPI.QueryBuilder().WithAll

com.unity.entities package version: 1.3.0-pre4

using Unity.Entities;
public struct ExampleComponent : IComponentData {
    public int Value;
}
public partial struct ChunkTestSystem : ISystem {
    void OnUpdate(ref SystemState state) {
        var query1 = SystemAPI.QueryBuilder().WithAllChunkComponent<ExampleComponent>().Build();
        var query2 = SystemAPI.QueryBuilder().WithAll<ExampleComponent>().Build();
    }
}

**In the source gen code, the query2 is considered to be the same as the query1 !!! **

the source gen code of ChunkTestSystem :

#pragma warning disable 0219
#line 1 "Temp/GeneratedCode/Assembly-CSharp/Test_Entities__System_6454372360.g.cs"
using Unity.Entities;
[global::System.Runtime.CompilerServices.CompilerGenerated]
public partial struct ChunkTestSystem : global::Unity.Entities.ISystemCompilerGenerated
{
    [global::Unity.Entities.DOTSCompilerPatchedMethod("OnUpdate_T0_ref_Unity.Entities.SystemState&")]
    void __OnUpdate_6D4E9467(ref SystemState state) {
        #line 7 "D:/UnityProject/Test/Assets/YX.Temp/Test_Entities.cs"
        var query1 =  __query_1805872340_0;
        #line 8 "D:/UnityProject/Test/Assets/YX.Temp/Test_Entities.cs"
        var query2 =  __query_1805872340_0;
#line hidden
    }

    
    TypeHandle __TypeHandle;
     Unity.Entities.EntityQuery __query_1805872340_0;
    struct TypeHandle
    {
        [global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
        public void __AssignHandles(ref global::Unity.Entities.SystemState state)
        {
        }
        
    }
    [global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
    void __AssignQueries(ref global::Unity.Entities.SystemState state)
    {
        var entityQueryBuilder = new global::Unity.Entities.EntityQueryBuilder(global::Unity.Collections.Allocator.Temp);
        __query_1805872340_0 = entityQueryBuilder.WithAllChunkComponent<global::ExampleComponent>()
.Build(ref state);
        entityQueryBuilder.Reset();
        entityQueryBuilder.Dispose();
    }
    
    public void OnCreateForCompiler(ref SystemState state)
    {
        __AssignQueries(ref state);
        __TypeHandle.__AssignHandles(ref state);
    }
}

But if the ChunkTestSystem only contains the query2, it will gen right code.

public partial struct ChunkTestSystem : ISystem {
    void OnUpdate(ref SystemState state) {
        var query2 = SystemAPI.QueryBuilder().WithAll<ExampleComponent>().Build();
    }
}

Source gen code:

#pragma warning disable 0219
#line 1 "Temp/GeneratedCode/Assembly-CSharp/Test_Entities__System_6454372360.g.cs"
using Unity.Entities;
[global::System.Runtime.CompilerServices.CompilerGenerated]
public partial struct ChunkTestSystem : global::Unity.Entities.ISystemCompilerGenerated
{
    [global::Unity.Entities.DOTSCompilerPatchedMethod("OnUpdate_T0_ref_Unity.Entities.SystemState&")]
    void __OnUpdate_6D4E9467(ref SystemState state) {
        #line 14 "D:/UnityProject/Test/Assets/YX.Temp/Test_Entities.cs"
        var query2 =  __query_1805872347_0;
#line hidden
    }

    
    TypeHandle __TypeHandle;
     Unity.Entities.EntityQuery __query_1805872347_0;
    struct TypeHandle
    {
        [global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
        public void __AssignHandles(ref global::Unity.Entities.SystemState state)
        {
        }
        
    }
    [global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
    void __AssignQueries(ref global::Unity.Entities.SystemState state)
    {
        var entityQueryBuilder = new global::Unity.Entities.EntityQueryBuilder(global::Unity.Collections.Allocator.Temp);
        __query_1805872347_0 = entityQueryBuilder.WithAll<global::ExampleComponent>()
.Build(ref state);
        entityQueryBuilder.Reset();
        entityQueryBuilder.Dispose();
    }
    
    public void OnCreateForCompiler(ref SystemState state)
    {
        __AssignQueries(ref state);
        __TypeHandle.__AssignHandles(ref state);
    }
}
1 Like