Generates code for creating EntityQuery objects bound to a system, working with both SystemBase and ISystem.
It supports using either the system itself as an entry point for the generator, or a struct defined inside the system.
OnCreate is not overridden — instead, a CreateDecoratedQueries method is added, which you must explicitly call from OnCreate. (Live Template for Rider is welcome).
EntityQuery definitions are expressed using WithWHATQ attributes, which essentially mirror the EntityQueryBuilder API (All, Any, Present, Chunks, including RW variants).
The attributes [SetChangeVersionFilterQ(typeof(T))] and [RequireForUpdateQ] are also supported.
I had two main goals with this code generator:
- Simplify passing EntityQuery/Singleton into polymorphic game loop constructs — you only need to pass the generated struct into the polymorphic call.
- Avoid having to think about BurstCompatible state.GetEntityQuery() and also about cleanup when creating an EntityQuery bound to the EntityManager rather than the system.
To declare under SystemBase, use [AutoQueries(true)].
To declare under ISystem, use [AutoQueries].
[UpdateInGroup(typeof(InitializationSystemGroup))]
[AutoQueries]
public partial struct RemoveEntitySystem : ISystem
{
[AutoQueries]
public partial struct Q
{
[WithAllQ(typeof(PhysicsTestCleanupTestRemove))]
public EntityQuery q;
[WithAllQ(typeof(PhysicsTestCleanupTestRemove))] [WithAllQ(typeof(PhysicsTestCleanupTestRemoveCleanup))]
public EntityQuery q2;
}
[RequireForUpdateQ] [ChangedVersionFilterQ(typeof(PhysicsTestCleanupTestRemove))] [WithAllQ(typeof(PhysicsTestCleanupTestRemove))]
public EntityQuery systemQ;
[WithAllQ(typeof(PhysicsTestCleanupTestRemove))] [WithAllQ(typeof(PhysicsTestCleanupTestRemoveCleanup))]
public EntityQuery systemQ2;
[WithAllQ(typeof(PhysicsTestCleanupTestRemove))] [WithAllQ(typeof(PhysicsTestCleanupTestRemoveCleanup))]
public EntityQuery systemQ3;
private int i;
private Q q;
private QOutside qOutside;
public void OnCreate(ref SystemState state)
{
this.q = new Q();
this.qOutside = new QOutside();
this.qOutside.CreateDecoratedQueries(ref state);
this.q.CreateDecoratedQueries(ref state);
this.CreateDecoratedQueries(ref state);
} [AutoQueries(true)]
public partial class ManagedTestSystem : SystemBase
{
[WithAllQ(typeof(PhysicsTestCleanupTestRemove))]
public EntityQuery q;
protected override void OnCreate()
{
base.OnCreate();
this.CreateDecoratedQueries();
}
protected override void OnUpdate()
{
}
}-->
partial class ManagedTestSystem
{
public void CreateDecoratedQueries()
{
q= new EntityQueryBuilder(Allocator.Temp).WithAll<global::RemoveTest.PhysicsTestCleanupTestRemove>().Build(this);
}
}