- Home /
OnDisable and OnDestroy Not Get Called - iOS
OnDisable and OnDestroy - these two methods were not get called in iOS. I have added these two method in MonoBehaviour object which get destroyed when game is closed.
Which ever data I was storing at game close time that not become available at next game launch time. So that I realise that these two methods were not working.
Any solution for this?
void OnDisable()
{
Debug.Log("*************************** OnDisable");
DataStorage.StoreLastOpenedDay(DateTime.Now.Day);
DataStorage.StoreLastOpenedMonth(DateTime.Now.Month);
DataStorage.StoreLastOpenedYear(DateTime.Now.Year);
}
void OnDestroy()
{
Debug.Log("*************************** OnDestroy");
DataStorage.StoreLastOpenedDay(DateTime.Now.Day);
DataStorage.StoreLastOpenedMonth(DateTime.Now.Month);
DataStorage.StoreLastOpenedYear(DateTime.Now.Year);
}
Answer by Tourist · Nov 10, 2017 at 10:35 AM
Hi,
Have you tested the code on other platforms (just to be sure it is iOs specific)? If so, have you been able to watch the log stream of the application (to be sure the OnDisable/OnDestroy logs are not shown)? Is there another class, this one is inherited of, that have those methods? If so you need to call base.OnDisable/OnDestroy?
If any of these fail, maybe you should consider sending a bug report to Unity.
Answer by FlaSh-G · Nov 10, 2017 at 10:36 AM
The two should be called properly. Is there a chance that your DataStorage methods are not instant, but rather start an asynchronous task?