/// <summary> /// Gets an <see cref="EntityQueryMask"/> that can be used to quickly match if an entity belongs to an EntityQuery. /// There is a maximum limit of 1024 EntityQueryMasks that can be created. EntityQueryMasks cannot be created /// from EntityQueries with filters. /// </summary> /// <param name="query">The EntityQuery that describes the EntityQueryMask.</param> /// <returns>The EntityQueryMask corresponding to the EntityQuery.</returns> public EntityQueryMask GetEntityQueryMask(EntityQuery query) { if (query.HasFilter()) { throw new Exception("GetEntityQueryMask can only be called on an EntityQuery without a filter applied to it." + " You can call EntityQuery.ResetFilter to remove the filters from an EntityQuery."); } if (query.m_QueryData->EntityQueryMask.IsCreated()) { return(query.m_QueryData->EntityQueryMask); } if (m_EntityQueryManager.m_EntityQueryMasksAllocated >= 1024) { throw new Exception("You have reached the limit of 1024 unique EntityQueryMasks, and cannot generate any more."); } var mask = new EntityQueryMask( (byte)(m_EntityQueryManager.m_EntityQueryMasksAllocated / 8), (byte)(1 << (m_EntityQueryManager.m_EntityQueryMasksAllocated % 8)), query.EntityComponentStore); m_EntityQueryManager.m_EntityQueryMasksAllocated++; for (var i = 0; i < query.m_QueryData->MatchingArchetypes.Length; ++i) { query.m_QueryData->MatchingArchetypes.Ptr[i]->Archetype->QueryMaskArray[mask.Index] |= mask.Mask; } query.m_QueryData->EntityQueryMask = mask; return(mask); }