Wrote about this in #1064581837055348857, but nobody had an answer so figured I'd make a larger post about it too.
The following system works fine:
using Unity.Collections;
using Unity.Entities;
public partial class TempSystem : SystemBase
{
public struct SomeComponent : IComponentData
{
}
public struct OtherComponent : IComponentData
{
public int SomeInt;
}
private EntityQuery _someQuery, _someAndOtherQuery, _someAndOtherQuery2;
protected override void OnCreate()
{
var builder = new EntityQueryBuilder(Allocator.Temp);
builder.WithAll<SomeComponent>();
_someQuery = GetEntityQuery(builder);
builder.WithAll<OtherComponent>();
_someAndOtherQuery = GetEntityQuery(builder);
builder.Reset();
builder.WithAll<SomeComponent, OtherComponent>();
_someAndOtherQuery2 = GetEntityQuery(builder);
builder.Reset();
}
protected override void OnUpdate()
{
// var queryToUse = _someAndOtherQuery;
var queryToUse = _someAndOtherQuery2;
if (queryToUse.IsEmpty)
{
EntityManager.CreateEntity(typeof(SomeComponent), typeof(OtherComponent));
}
Dependency = new TestJob().Schedule(queryToUse, Dependency);
}
private partial struct TestJob : IJobEntity
{
private void Execute(OtherComponent other)
{
}
}
}
But if I were to swap which query is being used, TestJob().Schedule will complain that the query doesn't cover all the components used in the Job. I think it's fine to enforce calling builder.Reset() after calling GetEntityQuery, but in that case it should error while making the query instead of creating a hard to debug error when using the query.
I've tested it with Entities 1.0.16 on Unity 2022.3.15f1 LTS, and Unity 2023.2.0b17