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 PokeyKapstone · Sep 17, 2018 at 08:27 AM · c#buttonstimescalefunctionsbutton trigger events

UI Button not calling function properly?

So I have a save point in my game where if you approach it and press a button, you enable a Canvas with three button options. I also set Timescale to zero and make it so the player can't move. This happens in Update() on a script attached to my save point object..

 if (playerHere && player.GetComponent<PlayerMovementTest> ().control == true && Input.GetButtonDown ("Submit")) 
         {
             eventSystem.GetComponent<EventSystem> ().SetSelectedGameObject(saveButton);
 
             player.GetComponent<PlayerMovementTest> ().control = false;
             Time.timeScale = 0;
             saveMenu.SetActive (true);
         }

So far so good. I have three buttons, Load, Save, and ClearSaves. Each button calls a function that looks something like this:

 public void SaveButton ()
     {
         //save the game, and take note of this save point specifically
         player.GetComponent<PlayerMovementTest> ().spawnPointNumber = spawnLocation;
         player.GetComponent<PlayerMovementTest> ().Save ();
         Debug.Log ("You saved at spawn point number " + spawnLocation);
 
         //turn off the canvas, and resume play
         saveMenu.SetActive (false);
         Time.timeScale = 1;
         player.GetComponent<PlayerMovementTest> ().control = true;
         Debug.Log ("End of function");
     }


Now the last half of this is what's giving me issue. When looking in the Console, I get the "End of function" log just fine, but the canvas never disables itself. and the timescale never gets set back either, despite me putting in a test Debug.Log that claimed it had returned to a value of 1, like it should. Everything just stays frozen and the buttons are still on screen.

But to make things even MORE confusing, just to test I tried calling the same SaveButton() function in Update through a keystroke.

 if (Input.GetKeyDown(KeyCode.Escape)) 
         {
             SaveButton ();
         }

And for some reason, this works! So apparently the button just isn't doing its job, despite the Debug.Log telling me otherwise. Does anyone know what on earth is happening here?

I'm using Unity 5.6 by the way.

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 LCStark · Sep 17, 2018 at 02:08 PM

Put a Debug.Log in the first block of code (the one where you stop the time and show your menu). Maybe it immediately pauses again after you've unpaused it?

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 PokeyKapstone · Sep 17, 2018 at 02:37 PM 1
Share

You're right, it does! The "Submit" Button is used for both opening the menu and pressing the button (which closes the menu), so it must be doing both in the same frame. That would explain why it works fine if I use the escape key ins$$anonymous$$d. Thank you!

avatar image
0

Answer by Jan_Julius · Sep 17, 2018 at 08:30 AM

Have you tried running it without setting timescale to 0? does this give you the same behaviour?

Comment
Add comment · Show 4 · 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 PokeyKapstone · Sep 17, 2018 at 08:34 AM 0
Share

I did, and it still left the canvas on screen, no difference.

avatar image Jan_Julius PokeyKapstone · Sep 17, 2018 at 08:49 AM 0
Share

What type is save$$anonymous$$enu?

Have you tried calling save$$anonymous$$enu.gameobject.setactive(false)

Capitalize where needed ^

avatar image PokeyKapstone Jan_Julius · Sep 17, 2018 at 08:58 AM 0
Share

save$$anonymous$$enu is a public GameObject that I assigned in the inspector. Just tried changing the code to that but it still gave the same effect... no luck :/ Thanks for the suggestion though.

Show more comments

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

91 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

Related Questions

cant run function when button pressed 1 Answer

Unable to show button after an event 0 Answers

Button Action Triggering Multiple Times Per Click? 1 Answer

How to copy and paste the color from one button to another button Unity C#?,How to copy a color of a button and past it on another button? 0 Answers

Multiple Cars not working 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