sschmid / Entitas

Entitas is a super fast Entity Component System (ECS) Framework specifically made for C# and Unity
MIT License
7.08k stars 1.11k forks source link

Trigger condition of Collector "component removed" in ReactiveSystem #932

Closed wangsihao87 closed 4 years ago

wangsihao87 commented 4 years ago

Hi,

I have a ReactiveSystem which collect entities with ComponentA removed, This system will be triggered when I call Entity.Destroy on the entity who has a ComponentA, the collected entity is fully empty (has no component), Is this the proper behaviour of Entitas? In my original thought, destoryed entity would not be conllected any way. If So What should I do to prevent the destroyed entity to be collected

Cheers

vayasandesu commented 4 years ago

I recommend marking an entity which you want to destory as ‘isDestroy’ = true instead of calling Entity.Destroy() immediately while ExecuteSystem or ReactiveSystem is running.

After all system execution completes, you can call Entity.Destroy() to destroy the entity which is marked ‘isDestroy’ from CleanupSystem.

wangsihao87 commented 4 years ago

I recommend marking an entity which you want to destory as ‘isDestroy’ = true instead of calling Entity.Destroy() immediately while ExecuteSystem or ReactiveSystem is running.

After all system execution completes, you can call Entity.Destroy() to destroy the entity which is marked ‘isDestroy’ from CleanupSystem.

Hi, It's not the same situation , I do real Destroy in a CleanupSystem. What I means is “Entity.Destroy()” which internally call “Entity.RemoveAllComponents()” would trigger xxxcomponent.removed() and the related reactiveSystem would excute. I think it's should not be a right behaviour? Nobody want to process a really destroyed entity, Am I right?

c0ffeeartc commented 4 years ago

Reactive system uses collector which collects entities, but not removes them until processed. Filter method can be used to check if entity still has relevant component.

sschmid commented 4 years ago

This is intended behaviour. You can filter for e.isEnabled to check if the entity is not destroyed yet.

There are scenarios e.g. counting destroyed entities where you actually want the reactive system to be able to process destroyed entities.