Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
This question was closed Mar 09, 2017 at 08:49 PM by WildRyce for the following reason:

Eventually managed to get scene switch working

avatar image
0
Question by WildRyce · Mar 09, 2017 at 04:35 AM · 2d gamescene-loadingscene-switchingfreezing

Game freezes after button is clicked to switch scenes

Hello,

I recently started 2D mobile development on Unity and don't know a whole lot about it as of yet (learning as I go). For the most part everything has been going fine, but there is one error I have come across that I can not find out at all.

When I run the game, its starts up fine and everything loads properly, but as soon as I swap scenes a few times using the buttons handling onClick(), it causes the app to freeze.

These are the buttons I use to switch scenes, which are located on each scene:

alt text

I have a small script setup for switching at the moment (I know it can be simplified to a single function and little amount of variables, this is just to help myself with referencing)

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.SceneManagement;
 
 public class SceneControl : MonoBehaviour {
 
     public void dungeonClick () {
         SceneManager.LoadScene ("DungeonScreen", LoadSceneMode.Additive);
             SceneManager.UnloadSceneAsync ("TavernScreen");
             SceneManager.UnloadSceneAsync ("ActivitiesScreen");
     }
 
     public void tavernClick () {
         SceneManager.LoadScene ("TavernScreen", LoadSceneMode.Additive);
             SceneManager.UnloadSceneAsync ("DungeonScreen");
             SceneManager.UnloadSceneAsync ("ActivitiesScreen");
     }
 
     public void activitiesClick () {
         SceneManager.LoadScene ("ActivitiesScreen", LoadSceneMode.Additive);
             SceneManager.UnloadSceneAsync ("DungeonScreen");
             SceneManager.UnloadSceneAsync ("TavernScreen");
     }
 }


The app originally froze when I first clicked to switch scenes, and I don't know what I did to lengthen the amount of time before it freezes. It went from first switch of a scene to four. I have tried looking through google for the longest time for a solution but all I can find is about LoadScene destroying the previous scene and creating the new scene.

I am separately unloading the other scenes because when I left the LoadScene normally, it would hang instantly on the button press after switching the scenes. When I tried this way it would allow switching a few times before it froze on a scene again.

I do have the C# Script in each scene connected to the canvases. I don't know what else may be helpful to understanding the problem I am having, but the error may be something very simple that I haven't realized for the past hours or so that maybe someone knows.

toimport.png (5.5 kB)
Comment
Add comment · Show 5
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 hexagonius · Mar 09, 2017 at 06:41 AM 0
Share

I'd like to know what happened when you used LoadScene (not additive) only? or is that what you did. if that already causes a freeze of try to replicate it in the editor. if that doesn't work check the profiler while running an development build.

avatar image WildRyce hexagonius · Mar 09, 2017 at 03:37 PM 0
Share

I have done the non-additive prior to using additive and that would cause it to freeze instantly after button press. I have found an error where it cant find a scene to unload, so I'm guessing that's what's causing the game to hang. Trying to find a way around it but no luck. Is there any way to open a scene without destroying the other scene at all, and not having multiple of the same scene open? Because there would be a lot of going back and forth between the scenes and it really starts to slow it down after 10 switches when all scenes are set to additive and none get destroyed.

avatar image hexagonius WildRyce · Mar 09, 2017 at 07:08 PM 0
Share

I just read the docs about UnloadSceneAsync and it essentially destroys all scene content like a normal LoadScene would do, just async.
If it's not too much of a load, why not loading all three scenes once and just change the current active one?

https://docs.unity3d.com/ScriptReference/Scene$$anonymous$$anagement.Scene$$anonymous$$anager.SetActiveScene.html

Show more comments

1 Reply

  • Sort: 
avatar image
0

Answer by WildRyce · Mar 09, 2017 at 08:49 PM

Managed to figure out a way to load and unload certain scenes using a master scene without it causing any errors.

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.SceneManagement;
 
 public class ButtonControl : MonoBehaviour {
 
     public void dungeonClick () {
         SceneManager.UnloadSceneAsync ("TavernScreen");
         SceneManager.LoadScene ("DungeonScreen", LoadSceneMode.Additive);
     }
 
     public void tavernClick () {
         SceneManager.UnloadSceneAsync ("DungeonScreen");
         SceneManager.LoadScene ("TavernScreen", LoadSceneMode.Additive);
     }
 }

Thank you @hexagonius for your help overall, got me thinking of a better way to load the scenes. Truly appreciated :D and surprised I didn't think of doing this earlier.

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 hexagonius · Mar 11, 2017 at 08:02 AM 0
Share

glad I could provide a different view angle

Follow this Question

Answers Answers and Comments

99 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

Related Questions

Player GameObject is not being positioned where my SceneController tells it to after scene transition. 1 Answer

Multiple Entrances to levels 0 Answers

Need a Script for Changing Scenes after pressing E to open locked door once a key has been found. 0 Answers

[Unity Beginner] Game design question on scene loading and scene transitioning 0 Answers

Why is my scene not loading? 2 Answers


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