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 /
avatar image
0
Question by Orolo · Oct 28, 2016 at 09:50 PM · scenescene-loadingscene-switching

How to ensure that an additively loaded scene is active before it becomes interactive?

I'm using the following code to load a scene additively that's supposed to become the active scene:

 SceneManager.LoadScene(scene, LoadSceneMode.Additive);
 yield return null;
 SceneManager.SetActiveScene(SceneManager.GetSceneByName(scene));

(scene is a string containing the name of the scene)

problem is, the scene can contain buttons that should only be clickable once the scene is actually the active scene. the way it is, the scene starts inactive and then becomes active. i want the scene to only show up when it's already active.

any way to do that?

Comment
Add comment · Show 2
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 SomeGuy22 · Oct 29, 2016 at 12:48 AM 0
Share

Have you looked at the Scene $$anonymous$$anager class? This might help if you want to see when a scene was loaded.

avatar image Orolo SomeGuy22 · Oct 29, 2016 at 09:30 AM 0
Share

edit:

have tested the delegate. it appears that unity is actually calling the sceneLoaded-delegate before the scene is loaded. hard to believe, but in this code, bla turns out to be false:

 private void OnSceneLoaded(Scene scene, LoadScene$$anonymous$$ode mode) {
     Debug.Log("OnSceneLoaded: " + scene.name + " FrameCount: " + Time.frameCount);
     bool bla = Scene$$anonymous$$anager.SetActiveScene(scene);
     Debug.Log(bla);
 }

according to the documentaiton for SetActiveScene, it returns false when the scene isnt loaded yet.

1 Reply

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

Answer by Orolo · Oct 31, 2016 at 03:16 PM

not super happy with it, but i've now done it this way:

changed my scene-loading-script from the three lines in the question to:

 SceneManager.LoadScene(scene, LoadSceneMode.Additive);
 yield return new WaitUntil(() => SceneManager.GetActiveScene().name == scene);

(the yield return because callers need to be able to wait until the loading is complete)

then made following script:

 using UnityEngine;
 using UnityEngine.SceneManagement;
 
 public class ActivateScene : MonoBehaviour {
     void Start() {
         bool wasLoaded = SceneManager.SetActiveScene(gameObject.scene);
         Debug.Assert(wasLoaded);
     }
 }

had to use Start because Awake and OnEnable are both called before scene is considered loaded.

added ActivateScene to Script Execution Order settings and put it before Default Time.

then of course, added an ActivateScene-component to every scene that needs to be auto-activated.

if anyone knows a better way, please let me know.

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 JairoGLoz · Feb 09, 2018 at 12:59 AM 0
Share

Nice solution man! thanks a lot!

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

,Enums not being passed between scripts properly 1 Answer

How can I have several scenes running at the same time? 1 Answer

SceneManager.GetAllScenes() only returns the current scene 3 Answers

Re-loading a scene but on the background older scenes are displayed 1 Answer

Load scene in editor playmode synchronously 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