I already know what is the problem. I found (singleton) MessagingManager game object at hierarchy of the <span style=”font-family: ‘Open Sans’, sans-serif; font-size: 12px; line-height: 24.2999992370605px;”>MainMenu scene. After I click New Game, OnDestroy function will be called and applicationIsQuitting variable in Singleton class will set to true. Then, the </span>(singleton) MessagingManager game object will be destroyed. So, when switch to new scene, as applicationIsQuitting variable is still remain true, it will still keep returning null and that’s why new (singleton) MessagingManager game object will never create again.
OK, going through this now and it is very odd.
Just put a load of logging data in and all the Singletons are being destroyed when loading The Main scene.
But The messaging manager isn’t even crated yet which is just odd. (actually it can’t be created because the FadInOutManager destroy has been called, which sets the “applicationIsQuitting” property, which in turn stops new Singletons from being created because Unity is closing)
Also for some reason OnDestroy is being called even though the FadeInOutManager is using “DontDestroyOnLoad”, which means it should only be called when it is actually destroyed when Unity closes / quits.
Hmm, going to investigate further as this smells like a new Unity bug.
In the sample code an instance of “MessagingManager” has been added to the “MainMenu” scene by default somehow.
As the type of singletons used in the book (programatic singletons), they are not meant to be added this way, so that is what is causing the error. Because it wasn’t created by Singleton, the DontDestroyOnLoad isn’t set, so when the GO is destroyed, it thinks the app is quitting.
To fix, just delete the “MessagingManager” from the “MainMenu” scene and it will run just fine.
Unsure how that got into the code download and can only apologise for the confusion there.
Simon (Darkside) Jackson
Viewing 5 posts - 1 through 5 (of 5 total)
The forum ‘Mastering Unity 2D Game Development’ is closed to new topics and replies.