Unity DOTS Entity Query Returns Empty - ECS Query and Component Fix - How to Fix
Problem Statement
You run a DOTS system, but your Unity DOTS Entity Query Returns Empty issue keeps happening:
- query count is always zero
SystemAPI.Query<...>()loop never entersEntityQuery.CalculateEntityCount()returns 0 even when you expect spawned entities- gameplay systems depending on ECS data do nothing
This is common in Unity 6 + DOTS projects, especially after moving to baking workflows.
Root Cause Explanation
In most cases, the query is not wrong by syntax. It is wrong by context.
Your query only matches entities in the current world that contain the exact required component set at the time the system runs.
Most empty-query bugs come from one or more of these:
- required components are missing or disabled
- entities were never baked/spawned in the world you are querying
- system update order runs before entities are ready
RequireForUpdateor additional filters accidentally exclude all entities- prefab/scene conversion assumptions changed after DOTS package updates
Quick Fix Solutions
Solution 1 - Verify Component Requirements Match Reality
- Print the exact component types required by your query.
- Check one expected entity in Entity Hierarchy and confirm all required components exist.
- Remove optional components from the query temporarily to test minimal matching.
- Reintroduce filters one by one.
Example pattern:
public partial struct MoveSystem : ISystem
{
public void OnUpdate(ref SystemState state)
{
var query = SystemAPI.QueryBuilder()
.WithAll<LocalTransform, MoveSpeed>()
.Build();
var count = query.CalculateEntityCount();
UnityEngine.Debug.Log($"MoveSystem query count: {count}");
}
}
If count appears after removing one component, that component is missing or not baked as expected.
Solution 2 - Confirm Baking Actually Produced Entities
- Check your Baker script runs for the authoring component.
- Verify converted entities appear in the correct world during play mode.
- Confirm the baker adds every runtime component your query needs.
- Rebuild/reimport subscenes if conversion data looks stale.
Typical oversight: baker adds LocalTransform but not your custom runtime tag used by the query.
Solution 3 - Fix System Update Order and World Context
- Ensure the system runs in the expected update group.
- Confirm you are querying the same world where entities exist.
- Add a temporary late-frame check to test if data appears later.
- If needed, move system after baking/spawn initialization systems.
If entity count is zero early and non-zero later, this is an ordering issue, not a query syntax issue.
Solution 4 - Audit Filters and RequireForUpdate Gates
- Temporarily remove
RequireForUpdate<T>()checks. - Disable extra query filters (
WithNone, changed filters, enableable-state filters) one at a time. - Re-test entity count after each removal.
- Restore only filters you truly need.
Many "empty query" bugs are self-inflicted by over-filtering.
Verification Steps
Run this sequence in order:
- Start play mode and log entity count from the target query.
- Confirm at least one entity contains all required components.
- Confirm system runs in correct update group and world.
- Confirm count stays non-zero across several frames.
- Confirm gameplay behavior now executes as expected.
Alternative Fixes (Edge Cases)
- Enableable components accidentally disabled
- Query may ignore entities when components are present but disabled.
- Subscene not loaded
- Entities exist in authored scene but are not loaded in runtime world.
- Runtime spawn path differs from bake path
- Spawned entities miss components baked entities have (or vice versa).
- Package version mismatch across team machines
- Conversion/runtime behavior differs after partial package upgrades.
Prevention Tips
- Keep query definitions small and explicit; add complexity gradually.
- Add one debug counter per critical ECS system in development builds.
- Standardize baker contracts so runtime systems know exact component sets.
- Document update-group expectations for each gameplay system.
Related Problems and Links
- If build-side DOTS compilation fails, see:
- If runtime behavior tree logic stalls, see:
- For official ECS references:
Bookmark this fix for quick reference. Share this article with your dev friends if it helped.