Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 WestonD · Feb 26, 2013 at 08:56 PM · guibuttonloadlevelinconsistent

GUI button inconsistent

I have implemented several GUI buttons to control scene loading in my game. My problem is the buttons on sceneMenu execute everytime. On sceneLoose, the one button executes almost every time. On sceneWin the next level button has to be clicked two or three times about every 4 calls to this scene. The menu button has to be spam clicked to even see the console print and never loads the menu scene.

For testing purposes I included a print in the controlling if statement to see if unity was seeing the button press. Indeed this print statement is being hit eventually on all but one button and when it prints to the console the level is loaded immediately. The other button is just never seen.

Also, the graphics of the GUI button are showing its being clicked.

Stripped down code follows:

 //SceneWin
 
 (Alot of Vars here)
 
 function OnGUI(){
 
 (Alot of Lables here)
 
     var nextLevelButton = GUI.Button(Rect(button1X,button1Y,button1W,button1H),"Next Level");
     
     var menuReturn = GUI.Button(Rect(button2X,button2Y,button2W,button2H),"Main Menu");
     
         if(nextLevelButton){
             print("Level Button Pressed, Loading");
             Application.LoadLevel("sceneLevel_1");
             }
         
         if(menuReturn){
             print("menu return pressed");
             Application.LoadLevel("sceneMenu");
             }
 
     
 }


Next Scene

 //sceneLoose
 
 //(virtually same vars as sceneWin)
 
 function OnGUI(){
 
 //(virtually same lables as sceneWin)
 
 
     var menuReturn = GUI.Button(Rect(button2X,button2Y,button2W,button2H),"Main Menu");
 
     if(menuReturn){
     
         player.PlayerReset();
         Application.LoadLevel("sceneMenu");
     
     }
 }
     

Menu scene

 //sceneMenu
 
 //(same vars, mostly, as other two scenes)
 
 function OnGUI(){
 
     var player = GameObject.FindWithTag("Player").GetComponent(scPlayer); //get player
 
     var startButton = GUI.Button(Rect(button1X,button1Y,button1W,button1H),"S T A R T");
     
     GUI.Label(Rect(label1X,label1Y,label1W,label1H), "Level Select");
     
     var levelSelectUp = GUI.Button(Rect(button2X,button2Y,button2W,button2H),"UP");
     
     
     GUI.Label(Rect(label2X,label2Y,label2W,label2H), "" + selectPlayerLevel);
     
     var levelSelectDown = GUI.Button(Rect(button3X,button3Y,button3W,button3H), "Down");
     
         if(startButton){
         
             Application.LoadLevel("sceneLevel_1");
             
             GameObject.FindWithTag("Player").GetComponent(scPlayer).SetPlayerState("levelEnd",false);
         
             print("start game");
             
         }
         
         if(levelSelectUp){
         
             selectPlayerLevel = selectPlayerLevel + 1;
             
             player.playerLevel = selectPlayerLevel;
         }
         
         if(levelSelectDown && selectPlayerLevel >1){
         
             selectPlayerLevel = selectPlayerLevel -1;
             
             player.playerLevel = selectPlayerLevel;
         }
     
 }
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 FLASHDENMARK · Feb 26, 2013 at 09:24 PM 1
Share

What about?:

 if(GUI.Button(Rect(button1X,button1Y,button1W,button1H),"Next Level")){
     //Load level here
 }
avatar image WestonD · Feb 26, 2013 at 10:37 PM 0
Share

Well, gave it a go and it didn't change the behavior. However I took a closer look at my log file. In the past it was just showing something along the lines of assets loaded/unloaded and I never saw my print statements in it. I just assumed that it had something to do with my game objects being destroyed and spawned in the game and after the next scene there was nothing to display in the log file because I was not hitting the print statement.

On close inspection (I have to scroll up some 100 paragraphs) I found the print statement. What follows is the log file from where the button is pressed and the last entry just keeps repeating and log file keeps growing.

Blockquote menu return pressed UnityEngine.Debug:Internal_Log(Int32, String, Object) UnityEngine.Debug:Log(Object) UnityEngine.$$anonymous$$onoBehaviour:print(Object) (at >C:\BuildAgent\work\812c4f5049264fad\Runtime\ExportGenerated\Edi>tor\UnityEngine$$anonymous$$onoBehaviour.cs:63) scWin:OnGUI() (at Assets\scWin.js:114)

(Filename: Assets/scWin.js Line: 114)

Unloading 1 Unused Serialized files (Serialized files now >loaded: 0 / Dirty serialized files: 0)

Unloading 4 unused Assets to reduce memory usage. Loaded >Objects now: 561. Operation took 22.295954 ms. System memory in use: 20.2 $$anonymous$$B. Unloading 0 Unused Serialized files (Serialized files now >loaded: 0 / Dirty serialized files: 0)

Unloading 0 unused Assets to reduce memory usage. Loaded >Objects now: 516. Operation took 6.055507 ms. System memory in use: 20.1 $$anonymous$$B. Unloading 1 Unused Serialized files (Serialized files now >loaded: 0 / Dirty serialized files: 0)

Unloading 4 unused Assets to reduce memory usage. Loaded >Objects now: 561. Operation took 11.681388 ms. System memory in use: 20.2 $$anonymous$$B. Unloading 1 Unused Serialized files (Serialized files now >loaded: 0 / Dirty serialized files: 0)

Unloading 4 unused Assets to reduce memory usage. Loaded >Objects now: 553. Operation took 15.612651 ms. System memory in use: 20.2 $$anonymous$$B. Unloading 1 Unused Serialized files (Serialized files now >loaded: 0 / Dirty serialized files: 0)

avatar image WestonD · Feb 26, 2013 at 11:43 PM 0
Share

Just another thought. I do have a singelton running (player). But its just :

 function Update () {
 
     
     if(levelEnd == false){
         
         ShotCheck();
     }
         else{
             
             EndLevel();
         }
     
 
 
 }    

and levelEnd is toggling as it should so its set to true during this GUI menu mess. That being said, the entries in the log may just be co$$anonymous$$g from it parsing that update thread.

avatar image WestonD · Feb 27, 2013 at 01:35 AM 0
Share

I wrote a quick project that uses 2 scenes each scene calling the other. In one of the scenes I placed a print function in update and observed the logs. Script and output follows. Debug Log

 nloading 1 Unused Serialized files (Serialized files now loaded: 0 / Dirty serialized files: 0)
 
 Unloading 4 unused Assets to reduce memory usage. Loaded Objects now: 515. Operation took 11.001113 ms.
 System memory in use: 11.9 $$anonymous$$B.
 Unloading 0 Unused Serialized files (Serialized files now loaded: 0 / Dirty serialized files: 0)
 
 Unloading 0 unused Assets to reduce memory usage. Loaded Objects now: 479. Operation took 5.471575 ms.
 System memory in use: 11.8 $$anonymous$$B.
 scene 2 start
 UnityEngine.Debug:Internal_Log(Int32, String, Object)
 UnityEngine.Debug:Log(Object)
 UnityEngine.$$anonymous$$onoBehaviour:print(Object) (at C:\BuildAgent\work\812c4f5049264fad\Runtime\ExportGenerated\Editor\UnityEngine$$anonymous$$onoBehaviour.cs:63)
 scene2:Start() (at Assets\scene2.js:7)

 //scene 1
 function OnGUI(){
     print("GUI Scene 1");
     Application.LoadLevel("scene2");
 }
 
 //scene 2
 function Start(){
     print ("scene 2 start");
 }
 function Update(){
     print("scene 2 update");
 }
 function OnGUI(){
     print("GUI Scene 2");
     Application.LoadLevel("scene1");
 }

The first thing I notice is that the same load/unload lines appear but they are getting cut off as the next scene loads. This leads me to believe that the Application.LoadLevel is never called despite the code being correct as far as I can tell. I'd call this a bug but not sure how to even prove its a bug.

avatar image WestonD · Mar 04, 2013 at 11:11 PM 0
Share

Im still getting this behavior with no clue why... just bumping it back up.

0 Replies

· Add your reply
  • Sort: 

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

10 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

Related Questions

Play sound on button click before loading level. 3 Answers

Loading scene with a prefab GUI button? 1 Answer

Change to scene based on current scene 1 Answer

Button then instanitates gameobject 1 Answer

How to hook up the particle system to jump animation? 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