Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 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 Unplug · Jan 30, 2018 at 06:08 AM · crashtoggle buttonhang

Possible Editor bug : Toggle crash / image not updating in editor

Hello, I really need help on this one, I have been seeking for solution and scroll hundreds of line of code just to see any mistake, but it's just a very basic toggle that produce the crash. Everything was working fine in past session but today i retest a toggle and it crash.

I have a serie of toggle that crash (hang) editor in play mode.

 void Awake(){
             EasyBtn.onValueChanged.AddListener(delegate { OnDifficultyChangeClick(1); });
             HardBtn.onValueChanged.AddListener(delegate { OnDifficultyChangeClick(2); });
             VeryHardBtn.onValueChanged.AddListener(delegate { OnDifficultyChangeClick(3); });
     }
     void OnDifficultyChangeClick(int MyChoice)
     {
         Debug.Log("My difficulty choice is " + MyChoice);
         if (MyChoice == 1)
         {
             EasyBtn.isOn = true;
             HardBtn.isOn = false;
             VeryHardBtn.isOn = false;
             InsaneBtn.isOn = false;
             CurrentDifficultyChoice = 1;
         }
         else if (MyChoice == 2)
         {
             EasyBtn.isOn = false;
             HardBtn.isOn = true;
             VeryHardBtn.isOn = false;
             InsaneBtn.isOn = false;
 
             CurrentDifficultyChoice = 2;
         }
         else if (MyChoice == 3)
         {
             EasyBtn.isOn = false;
             HardBtn.isOn = false;
             VeryHardBtn.isOn = true;
             InsaneBtn.isOn = false;
 
             CurrentDifficultyChoice = 3;
         }
         else if (MyChoice == 4)
         {
             EasyBtn.isOn = false;
             HardBtn.isOn = false;
             VeryHardBtn.isOn = false;
             InsaneBtn.isOn = true;
 
             CurrentDifficultyChoice = 4;
         }
         else
         {
             Debug.Log(MyChoice);
         }
     }
 

The DebugLog doesn't even get called, so it look like the problem is with the listener !?

The weird thing I see in the editor is that the image preview in the inspector doesn't show up for the problematic toggle. The image preview is blank (alpha). When I uncheck and recheck the gameobject the preview regenerate correctly. When I look in window sprite packer the correct image is there, I thought it could be a corrupted sprite pack, but I don't know how to force a regeneration. I also tried reimporting the image and deleting the meta to force recreation but nothing have improved.

Any clue ?

Comment
Add comment
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

2 Replies

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

Answer by Unplug · Jan 30, 2018 at 08:02 PM

So one solution is to rely on the name of the item being click instead of just pushing an integer as the name of the object being clicked won't change no matter if the value of any toggle change. The disadvantage of this, is that the "onvaluechange" still trigger and you loose some computing power for no reason, but considering the low amount of toggle and speed of such action, it is not a problem. Maybe someone will come up with a better solution or maybe unity will allow us to use a onClick function for toggle...

 void Awake()
 {
         EasyBtn.onValueChanged.AddListener(delegate { OnDifficultyChangeClick(EventSystem.current.currentSelectedGameObject.name); });
         HardBtn.onValueChanged.AddListener(delegate { OnDifficultyChangeClick(EventSystem.current.currentSelectedGameObject.name); });
         VeryHardBtn.onValueChanged.AddListener(delegate { OnDifficultyChangeClick(EventSystem.current.currentSelectedGameObject.name); });
         InsaneBtn.onValueChanged.AddListener(delegate { OnDifficultyChangeClick(EventSystem.current.currentSelectedGameObject.name); });
 }
 
     void OnDifficultyChangeClick(string ToggleName)
     {
         Debug.Log("My difficulty choice is " + ToggleName); //I have 3 toggle, so the whole loop get called twice. Since the togglename doesn't change without a new click, the loop end.
         
         if (ToggleName == EasyBtn.name)
         {
        
             EasyBtn.isOn = true;
             HardBtn.isOn = false;
             VeryHardBtn.isOn = false;
             InsaneBtn.isOn = false;
             CurrentDifficultyChoice = 1;
         }
         else if (ToggleName == HardBtn.name)
         {
             EasyBtn.isOn = false;
             HardBtn.isOn = true;
             VeryHardBtn.isOn = false;
             InsaneBtn.isOn = false;
 
             CurrentDifficultyChoice = 2;
         }
         else if (ToggleName == VeryHardBtn.name)
         {
             EasyBtn.isOn = false;
             HardBtn.isOn = false;
             VeryHardBtn.isOn = true;
             InsaneBtn.isOn = false;
 
             CurrentDifficultyChoice = 3;
         }
         else if (ToggleName == InsaneBtn.name)
         {
             EasyBtn.isOn = false;
             HardBtn.isOn = false;
             VeryHardBtn.isOn = false;
             InsaneBtn.isOn = true;
 
             CurrentDifficultyChoice = 4;
         }
         else
         {
             Debug.Log(ToggleName);
         }
         
     }
 
 

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 Commoble · Jan 30, 2018 at 06:16 AM

When Unity hangs with no error message or crash log, it typically means you've caused an infinite loop. If I'm reading your code correctly, your listeners call your OnDifficultyChangeClick method whenever the values of your button change. This function then changes the values of each of your buttons, which causes OnDifficultyChangeClick to be called again for each of those buttons., which changes the value of each of your buttons again. This is an infinite loop.


You'll need to rework how your interface works; you probably shouldn't have your buttons directly altering your other buttons. One suggestion (only the first thing I thought of, not necessarily the best) have the buttons just change CurrentDifficultyChoice, and then have the buttons check that value in an update loop and update their appearance accordingly.

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 Unplug · Jan 30, 2018 at 02:03 PM 0
Share

$$anonymous$$mmmmh i wasn't seeing this as a loop since there is no for and while and that the function is called with an integer and I was treating that integer in the if and the integer doesn't change. That said, the value of the toggle get change and that is definitely recalling the toggle function over and over !! Thanks for the heads up. I'll post a solution. It was first buttons, not that it is toggle, I will consider using a toggle group to fix the situation and i'll repost the solution

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

79 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

Related Questions

Unity 2017.3.0bf freezing on Play when switching windows? 0 Answers

Adding FixedJoints causing crashes and hangs 1 Answer

Editor Hangs after first play using plugin DLL 2 Answers

Memory Crash / Hang on build Unity 4.5.3f3 1 Answer

Unity hangs when attached to MonoDevelop 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