When call EntityManager.DestroyEntity(EntityQuery) it will throw if entity with LEG containing self (usual behaviour) and disabled enablable component (properly handled in query). Consider that as a bug @hidden nova As AssertWillDestroyAllInLinkedEntityGroup checks chunks before destroy actually gather entities for destroy. As result we have chunk with 2 entities, where one is disabled and one is enabled, and AssertWillDestroyAllInLinkedEntityGroup not respect entities enabled state on check for LEG buffer accessor(but actual destroy - does), it iterates through all LEG's in chunk even if entity in chunk has component which is disabled and part of query and wouldn't be included in resulting batch to destroy which means for this entity iterate through it’s LEG and validity check is useless, but it still happens.
#[Bug] EQ Destroy with disabled components and LEG
1 messages · Page 1 of 1 (latest)
Example
As you can see entities only contain self in LEG. The thing is actual destroy will do the job properly, if AssertWillDestroyAllInLinkedEntityGroup wouldn't fail on check (happens before actual destroy)
(Moved discussion to separate thread from dots chat to exclude chat noise)
Thanks, I've taken note, will repro and write something up later
[Bug] EQ Destroy with disabled components and LEG
What version is this with?
Tested in latest 1.3.5 Entities but that logic is there since 1.0.10
So just eyeballing the code, I'm guessing building the query with WithPresent<Destroy> works
I'm not sure I agree that the behavior is a bug, I wouldn't want to introduce special semantics for the query just in DestroyEntity
It will be different behaviour
WithAll explicitly means - I want to get entities and respect eneblable state
Which means we just cant have query destroy with disabled root entities with leg
yeah, obviously that's not right

just thinking through what semantics we need to preserve
We of course can pass native array from ToEntityArray, but… it smells a bit 
The problem here is only this leg check
well LinkedEntityGroup is kind of cursed to begin with
Well yep
And what more cursed in this exact case is that entity itself present in leg, otherwise this check would work, because other “nested” recursive leg’s checks will work just fine and properly will check linked entites enabled state, and disabled root entity (as not being present in any leg in default case) would ignore that check. But yeah there is additional check required, which will tell, based on initial query if specific root leg’s from buffer accessor should be skipped if root entity considered disabled by query.
Never got the reason why entity itself present in leg, as we anyway pass “root” entities when destroy/instantiate and have information about them is there specific reason for that?
(just never thought to check about why it can be required)
I'm not sure how this is different from just the normal case that entities in a LEG have disjoint componens
Let’s imagine have E1 E2 E3 E4 E5 E6. All of them, except, let say E6, have enablable comp A and whole lot of other components, disabled enabled etc. E1 has leg with E1, E2, E3. And E3 has leg with E3, E4, E5. And E4 has leg with E4, E6. Pretty mixed. And let’s say E1 A is disabled. We have query WithAll<A>. Which returns us all entities except E1 and E6. We call destroy on that query. What should we expect here, well by default all entities match query should be destroyed right? Which means it should destroy all E2-E5 entities explicitly by query and E6 implicitly (as part of E4 leg), and E1 should stay because it’s not part of initial entities matching query, it’s disabled and by WithAll<A> query it treated the same as it doesn’t have A at all, but that’s not the case right now as it fails on E1 leg check which shouldn’t happens at the first place, as LEG accessor we get from query shouldn’t return us LEG for E1 (or at least it should skip). Currently is like we call destroy on entities with component X and LEG through query WithAll<X>and it fails just because there is entities with Y and LEG (without X) exists in a world and query WithAll<X>.GetBufferAccessor<LEG> returns us them too.
Thanks, that makes sense. The assert code as you've probably noticed walks the LEGs without respect to whether the containing entity matches the query. Debating how narrow to make the fix internally
Cool!
Was there a ticket made for this one?
yes, and in fact I'm sitting on the fix, just have to clean up one other thing first that is taking some time
Nice, top tier support, DOTS chief fix bugs himself!