See the image below -- Pretty much, I have LobbyUI and LobbyMgr gameObjects at top level of the hierarchy.
In each resides lobbyUI.cs and LobbyPhoton.cs, respectively.
When I start the game, TWO awake() and TWO start()'s happen.
I tried to find the path on awake in the hierarchy -- well, it's at /LobbyUI and /LobbyMgr at the top! That's normal. Check for dupes? Nothing there... nothing unusual....
Well, what about on awake, if the singleton is null, assign - else destroy. IT'S CLEARLY NOT NULL, YET SKIPS THE IF (S == NULL) LOGIC!! .............What.....?!?
I'm so confused lol halppp
Update 1: I ctrl+F'd through every single instance of the entire solution with the name of the class. Not ONE instance -- all singleton refs. What is going on.................. Both the dupes have unique instance IDs and even the game object parents have unique instance ids .... yet there's only 1 of each! I even tested for the hierarchy location: both at root, where there's only 1 gameObj with 1 script attached. Ahhhhh! O__o lol
Answer by dylanh7244
Mar 13 at 02:23 PM
Found the answer -- TL;DR caused by async tasks not finishing up before loading (it sounds unlikely, but I swear it and reproduced/fixed it) - if I wait for them to finish (or the ghetto version of waiting 0.1sec before changing scenes), EVERYTHING is resolved.
Unity needs better garbage collection for unfinished async tasks on change scene.
(I reported the bug after being able to reproduce it every time)
What happened If you change scenes while async tasks are still going, it will bug the hell out of the next scene. I had 2 completely irrelevant scripts that would awake() twice, sometimes even times.
They were confirmed multiple instances of these 2 scripts (lobbyUI and lobbyPhoton), including the parent gameObj's (LobbyUI and LobbyMgr). I would even trace where they are in the hierarchy and it'd always say top level at /LobbyMgr and /LobbyUI, where I would always see only ONE.
Not only that, ALL USES were singletons so the situation is impossible unles I dropped it in 2 gameObj's by accident, but I'd "find all references within scene" and nope -- just the 1's.
On Awake() if I tested for null for the singleton, it would SKIP the logic (it was clearly NOT null) and make a singleton of itself, anyway.
This is a HORRIBLE HORRIBLE bug that took me days to debug.
RESOLVED by waiting for 0.1 second before swapping scenes. Literally this was the solution. I found out there were some unfinished async tasks. Surely the non-lazy resolution would be to check all of the callbacks to ensure they are all done.
Either way, Unity needs better garbage collection when changing scenes for async tasks that are incomplete.
See attached screenshot
Relevant post @ http://answers.unity3d.com/questions/1325286/async-code-on-scene-change.html#answer-1325401
Hey, just because im curious... where is that "consoleE" window from, that you show in the picture?
Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.
The best place to ask and answer questions about development with Unity.
To help users navigate the site we have posted a site navigation guide.
If you are a new user to Unity Answers, check out our FAQ for more information.
Make sure to check out our Knowledge Base for commonly asked Unity questions.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, see the list of changes.
Answers and Comments
102 People are following this question.
Is this a bug in MonoDevelop? I do NOT see what is wrong
Start is not called after reloading the level
Why isn't my mobile single joystick showing on screen, PLEASE HELP?
Unity 5.2.1 image ui bugs
iPhone 5 distorted 3D models