- Home /
Why Unity stops call OnUpdate in the ComponentSystem after an entity destroy?
Hi everybody,
I have one tricky problem - I have the one ComponentSystem in my project, and I do some code in the OnUpdate function. Everything goes well until I try to destroy the entity, like
EntityManager.DestroyEntity(myEntity)
After that Unity stops calling the OnUpdate function in the ComponentSystem (I checked with the debugger too) without any errors or something.
My Unity version - 2020.1.4f Entities package version - 0.14.0-prewiev.19 Hybrid Renderer package version - 0.8.0-prewiev.19
Thank you for your help ;)
Answer by andrew-lukasik · Sep 16, 2020 at 11:12 AM
Unity analyses code of your system to create lists of component types your system is interested in processing (EntityQuery, Entities.ForEach(T1,T2,...) etc). OnUpdate will be called when there is at least single object/entity fitting the criteria and stops being called when there is none.
There is a way to get around this wise optimization with AlwaysUpdateSystem attribute. But you don't wan't to use it everywhere without understanding this mechanism first.
Your answer
![](https://koobas.hobune.stream/wayback/20220613011654im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Get GameObject dependencies only once for JobComponentSystem 1 Answer
Can the burst compiler be used for any code? 0 Answers
Does DOTS have a animation component? 1 Answer
Unsafe.dll from Unity version conflicts with Unsafe.dll from standard collections package. 1 Answer
I'm not seeing a performance increase with the Job System. Help 1 Answer