OnEnable/OnDisable is not always called when quickly disabling and reenabling an object.

When you disable and re-enable on object in the same frame (pooling) OnDisable and OnEnable can sometimes be never called. even waiting a frame doesn’t always fix this when the engine is under heavy load. We are now waiting .5 seconds before re-enabling a pooled object and that fixes the issue.

I’m guessing Unity is under the hood only updating x number of objects per frame when they are disabled/re-enabled? So doing a mass pool/unpool at load time would cause this issue. Is that correct? (we pool everything even if it is instantly loaded for code path consistency)

We don’t have time to create a proof case of this as the engine works fine until its under heavy load and with the unity QA process we’d need to create a scene that re-creates that load.

Having the same problem, I can also confirm this issue.
And .5 seconds is no good solution as it differs per platform and per machine.

Didi multithreading solve your problem?

We didn’t multi-thread. We simply wait .5 seconds (we are console so we know we have a consistent platform). .2 seconds wasn’t long enough. So its a pretty big issue when the engine is under heavy load. This is an issue in the unity engine where I’m guessing that they are caping the number of objects per frame that can be enabled or disabled.

For me, OnDisable() is never called under any circumstances when the object is deactivated by another script. Is it only called when deactivated by the same script?