Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by MrLucid72 · Mar 13, 2017 at 07:10 AM · bugbug-perhapsbugssingleton

Start()/Awake() being called twice, after already checking for dupes!

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

Test+Results

wtfffff.jpg (352.5 kB)
Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image MrLucid72 · Mar 13, 2017 at 09:41 AM 0
Share

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

4 Replies

· Add your reply
  • Sort: 
avatar image
6
Best Answer

Answer by MrLucid72 · Mar 13, 2017 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

alt text

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Desoxi · Mar 13, 2017 at 02:44 PM 0
Share

Hey, just because im curious... where is that "consoleE" window from, that you show in the picture?

avatar image ranger0550 · Jul 24, 2018 at 03:02 PM 0
Share

Still exists in 2018.2.0 - thanks to your comment I solved my issue with "multiple Awake() call". ;) Edit: In my case I use standard: Scene$$anonymous$$anager.LoadScene(name) because asynchronous loading was redundant. ;)

avatar image
0

Answer by ArshakKroyan · Oct 25, 2018 at 07:19 AM

Hi. Recently I also had such an issue. Awake() was called twice when I exited from play mode. After some research through SmartGit change-logs found out that the error was after I had added [ExecuteInEditMode] for the Script.

I hope this will help others also.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by unity_VvCODKknmBJQGw · Jun 01, 2021 at 04:26 PM

Note that the "wait for 0.1 seconds" is kinda brute... Might wanna use:

 await Task.WhenAll(_asyncOperations);


Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by tomosbach · Aug 02, 2021 at 08:43 AM

I. Feel. Your. Pain.

I spent howwwwwwwuuuuurrrrrsssssss trying to resolve this problem, before realising that Unity was calling up the scene twice because of Async, despite me having copied the API example word for word. This meant that all of my events kept breaking because they were trying to call up destroyed objects from the first instance of the scene.

Thank you so much though, your post probably saved me from spending the rest of my life in a mental instituion.

@Unity. WhatsUpWithThat?

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image tomosbach · Aug 02, 2021 at 08:45 AM 0
Share

Aaaaaah I see this post is actually 3 years old, so I'm guessing there is no resolution on the horizon, eh :'(

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

102 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Random image appears in the center of the screen while using scrollrect 1 Answer

Big bug in all materials 0 Answers

Play mode enters full screen/ cant exit? 1 Answer

UnityEngine.UI.Image keeps removing itself from a Prefab. 1 Answer

When using a Gameobject variable in a public void in C# it does not show up in button(script) 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges