#SystemAPI generating wrong code

1 messages · Page 1 of 1 (latest)

lone forge
#

There seems to be some kind of issue when using SystemAPI.QueryBuilder inside system properties. The generated query is missing the WithAll parameter and not working properly.
When defining the query inside a method instead of a property it works correctly.

Am I doing something wrong or is this a Unity bug?

Code:

public partial class TestSystem : SystemBase
{
    public struct TestComponent : IComponentData
    {
        public int A;
    }

    public Entity MyEntity => SystemAPI.QueryBuilder().WithAll<TestComponent>().Build().GetSingletonEntity();

    protected override void OnUpdate() { }
}

Generated Code:

[global::System.Runtime.CompilerServices.CompilerGenerated]
public partial class TestSystem
{
    [global::Unity.Entities.DOTSCompilerPatchedProperty("TestSystem.MyEntity")]

    Entity __MyEntity_6A13DB69 =>  __query_1809747855_0.GetSingletonEntity();
    
    TypeHandle __TypeHandle;
     Unity.Entities.EntityQuery __query_1809747855_0;
// ...
    [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_1809747855_0 = entityQueryBuilder.Build(ref state);
        entityQueryBuilder.Reset();
        entityQueryBuilder.Dispose();
    }
// ...
}
willow hornet
#

first problem is you are using a property on an ISystem 🙈

lone forge
#

yeah, for the ISystem it doesn't actually makes sense... I've updated the post
but I don't see any reason for it not working on SystemBase?

celest moth
lone forge
#

I don't see why would properties would be finicky though, it's a pretty common language feature
I'll file a bug report soon... there should at least be a warning in case they don't intend to support proper code gen on properties

serene notch