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 Apr 08, 2016 at 01:22 PM by Ryanless for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Ryanless · Apr 06, 2016 at 08:42 PM · gamescene-switching

mainmenuscript keeps crashing the game

So i have made this mainmenu-script which works perfectly fine, if u start in mainmenu and then load a lv. Going from any lv to mainmenu works fine too. But if go from a lv to mainmenu and then try to access any lv the game crashes. I tried modifying it a bit, but that made it worse, so i reset to a way i know it works at least a bit. Can someone tell what's causing the bug?

Maybe some additional bug behaivour note, once the bug is caused and everthing frozen, u can simply, pause and unpause to get a gameover screen, which reloads same lv and suddenly its fine.

Here the code i wrote:

 using UnityEngine;
 using System.Collections;
 using UnityEngine.SceneManagement;
 using UnityEngine.UI;
 
 
 public class MainmenuManager : MonoBehaviour {
 
     //CanvasGroup HUDCanvasgroup;
 
     // Use this for initialization
     void Start () {
 
         //GameObject HUDCanvas = GameObject.Find ("HUDCanvas");
         //HUDCanvasgroup = HUDCanvas.GetComponent<CanvasGroup> ();
     }
     
     // Update is called once per frame
     void Update () {
     
         if (Input.GetKeyUp (KeyCode.Escape)) {
             quit();
 
         }
     }
     
     // loads the lv with number lv
     public void loadLevel(int lv){
         SceneManager.LoadScene (lv);
 
     }
         
     //ends the programm
     public void quit(){
         Application.Quit();
     }
 
     public void gotoMainmenu(){
         SceneManager.LoadScene ("Mainmenu");
             }
 
 }
Comment
Add comment · Show 4
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 Jessespike · Apr 06, 2016 at 09:03 PM 0
Share

Select all of the code and press the "101010" button, it's inbetween the Blockquote and the Attachment button. Also paste the error that you are encountering, or is it crashing and closing Unity without outputting an error?

avatar image Ryanless Jessespike · Apr 07, 2016 at 02:00 AM 0
Share

Thx, that looks already nicer. Nah just the game window frezes and no error output when that happens. To add to music and rest is not affected by the gamefreeze. I do get sometimes a "Error adding System: Data not avaiable" though no link to a script nor a gameobject, so not really helpful.

oh and i managed to "fix" as far that the "pause trick" doesnt cause a instant game over but let u play right away without reloading the scene.

avatar image Jessespike · Apr 07, 2016 at 06:00 PM 0
Share

I don't see any problems with the script. There must be something else going on in the scene. Do you have scripts that have DontDestroyOnLoad? Unity shouldn't crash so easily, it's a strange problem here.

avatar image Ryanless Jessespike · Apr 07, 2016 at 10:32 PM 0
Share

ok, fixed it. Thx for the help finally i can finish this project for good :-D Yep it was something that doesnt DestroyOnLoad but not a gameObject but the variable: time.TimeScale which seems to be a global instance and not diffrent for every lv. (weird) It's not indicated (hinted at best) that its influences all scenes in the Scripting API.

Pause turned timeScale to 0. So now i turn it to 1 before loading the lv.

Is there a list of all build in global variables which DON'T change, when loading a new scene?

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

68 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

Related Questions

Game build often crashes when switching scenes 0 Answers

My Android game is lagging.. 0 Answers

Animation Scripting Issue,Walking Animation Script Not Working 0 Answers

Sprite looks different in game than in editor 0 Answers

UNITY REMOTE 5 WORKS IN ANDROID 9.0??? 0 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