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 AndyMartin458 · Jan 16, 2014 at 05:04 AM · key pressedunity inputtext inputpressing

2/3 times pressing a button does nothing.

I am using the Input.GetButtonDown function to detect input for a lot of my buttons. I want the inputs to only be able to cause 1 action which is why I'm using GetButtonDown. The problem is that it doesn't always register, even if I press the button all the way down. This will happen more frequently of course if I press the button faster, but sometimes even if I haven't pressed the button recently, it still does not register.

I am calling these button presses from FixedUpdate. Is there a way to register every time the button is pressed to keep from missing any GetButtonDowns?

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

1 Reply

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

Answer by robertbu · Jan 16, 2014 at 05:06 AM

Calling from FixedUpdate() is likely your problem. Try calling them from Update() instead, setting some boolean flags if the button-press code must be executed in FixedUpdate().

Comment
Add comment · Show 8 · 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 AndyMartin458 · Jan 16, 2014 at 06:16 AM 0
Share

@robertbu yes, thank you, that did it. I thought that calling it from FixedUpdate would make it more responsive because it would get called more regularly. Do you know why that's not the case?

avatar image Unity_gamer · Jan 16, 2014 at 06:51 AM 2
Share

Check this link , It explains the difference clearly .

avatar image robertbu · Jan 16, 2014 at 06:52 AM 0
Share

Here is my guesstimation of the issue based on my visualization of how this all works (and why I made the suggestion to go to Update()). GetButtonDown() will be true during a single Update() frame. It may not even be the full deltaTime of that frame, just the duration of all the Update() calls for that frame. When the frame rate is high, or if the frame rate is uneven, then the frame that gets the GetButtonDown() can fall between FixedUpdate() calls. The default FixedUpdate() rate is 50 fps. Imagine that your Update() calls are running at 120 fps. $$anonymous$$any Update() frames will start and end between FixedUpdate() calls, and these $$anonymous$$ouseDown events will be lost if you are only checking in FixedUpdate().

avatar image AndyMartin458 · Jan 16, 2014 at 07:34 PM 0
Share

@robertbu I thought that I had looked at the page here so many times before, but I must not have ever carefully read it. http://docs.unity3d.com/Documentation/ScriptReference/30_search.html?q=GetButtonDown It specifically says to use Update. Thanks to your insights, I now understand why that is important.

avatar image robertbu · Jan 16, 2014 at 08:36 PM 0
Share

I converted my comment into an answer. @Duck's answer does a through job of explaining. Thanks @Unity_gamer.

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

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

How to move an object with a key input? 0 Answers

Problem With Walking Sounds 1 Answer

Play sound by pressing button 2 Answers

On button press/hold = input from a keyboard? 1 Answer

Need delayed reaction after key press 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