Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 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
1
Question by Superwayne · May 13, 2013 at 10:12 PM · pausekeyboard

Get Input while Time.timescale == 0?

Hey,

I want to controle my pausemenu by keyboard input but Time.timescale is set to 0 for pausing the game. Is there another way to perform keyboard input based events than using the updatefunction?

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

3 Replies

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

Answer by rutter · May 13, 2013 at 10:19 PM

Active components should still get Update() calls while time is frozen, but bear in mind that Time.deltaTime will always be zero (this can cause funky behavior if you're not expecting it). If it's not being called, your component is probably missing or inactive.

It's simple enough to test if Update() is getting called by putting a simple log statement in there.

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 Superwayne · May 13, 2013 at 10:33 PM 0
Share

Oh, stupid me trying to use "GetAxis" ins$$anonymous$$d of "GetButton".. Forgot that Axis take time until they reach 1/-1.. so while timescale is set to 0 they will stay at 0.. Thanks and Sorry ;)

avatar image rutter · May 13, 2013 at 10:45 PM 0
Share

No problem! That's why we're here. :)

$$anonymous$$y classic mistake is pausing, then wondering why UI animations stop moving.

avatar image TheDarkVoid · May 13, 2013 at 10:51 PM 1
Share

also as an addition you could do 1/curFrameRate to allow you to still do time based animations without being affected by Time.deltaTime.

avatar image knightpraetor · Sep 05, 2017 at 08:11 AM 0
Share

If I use EditorApplication.isPaused to pause the editor, how do i unpause it from a script? none of the scripts will get update functions then, right?

Is that why everyone seems to be using Time.timescale = 0 ins$$anonymous$$d?

I kind of want the editor buttons to match the current state properly when i'm debugging.

all i really wanted was to have a different hotkey to pause the editor because the one they chose was a pretty poor choice. Can't use the mouse and pause with just two hands

avatar image
18

Answer by Tabemasu Games · Sep 08, 2014 at 04:19 PM

You can also use the Input.GetAxisRaw method, which will work even when timeScale = 0.

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
2

Answer by joshluna · May 24, 2020 at 12:13 PM

GetAxis uses Time.deltaTime to smooth the value by Sensitivity/Gravity settings from the Input configuration, therefore it respects Time.timeScale. You can use GetAxisRaw, but that will no longer respect Sensitivity/Gravity. This will apply smoothing using Time.unscaledDeltaTime, but it might produce different results, not sure exactly how GetAxis resolves.

 private void GetSmoothRawAxis(string name, ref float axis, float sensitivity, float gravity)
 {
     var r = Input.GetAxisRaw(name);
     var s = sensitivity;
     var g = gravity;
     var t = Time.unscaledDeltaTime;
 
     if (r != 0)
     {
         axis = Mathf.Clamp(axis + r * s * t, -1f, 1f);
     }
     else
     {
         axis = Mathf.Clamp01(Mathf.Abs(axis) - g * t) * Mathf.Sign(axis);
     }
 }

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 Knugke · Feb 03, 2021 at 09:29 PM 0
Share

Thanks, this solved my issue of not being able to scroll around my map with the game paused. It looks pretty spot on compared to GetAxis!

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

20 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

Related Questions

Controlling pause menu with keyboard in Unity 4.6? 1 Answer

Pause Game Through Button UI Click Instead of Escape Key? 2 Answers

Android keyboard pauses app, and doesn't release it 1 Answer

Script Not workin 1 Answer

Pausing game 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