Search Unity

  1. Check out our Unite Austin 2017 YouTube playlist to catch up on what you missed. More videos coming soon.
    Dismiss Notice
  2. Unity 2017.2 is now released.
    Dismiss Notice
  3. The Unity Gear Store is here to help you look great at your next meetup, user group or conference. With all new Unity apparel, stickers and more!
    Dismiss Notice
  4. Introducing the Unity Essentials Packs! Find out more.
    Dismiss Notice
  5. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice
  6. Unity 2017.3 beta is now available for download.
    Dismiss Notice

Input.GetButtonDown not working...

Discussion in 'Editor & General Support' started by Iron-Warrior, Apr 7, 2010.

  1. Iron-Warrior

    Iron-Warrior

    Joined:
    Nov 3, 2009
    Posts:
    639
    Howdy Unityers,

    Been fiddling around with Unity and have encountered a curious problem. Input.GetButtonDown() doesn't seem to always register...and I can't find any reason at all for it.

    When I put this code into a FixedUpdate()

    Code (csharp):
    1.     function FixedUpdate () {
    2.     if (Input.GetButtonDown("Fire1"))
    3.     {
    4.             Debug.Log(Time.time);
    5.             //Jump();
    6.     }
    7. }
    Each time I click it should update the time in my debugger, right? Well, sometimes it just misses it. Fire1 is mapped to either the left mouse or the ctrl key, and this problem happens if I use the ctrl key or the mouse button. Sometimes when I click, it just doesn't register at all...no other variables or conditions at all. You can copy this code, apply it to an object and click away to see the problem. Is this a known bug? I was searching around and didn't seem to find anything...

    Thanks for any help!
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    31,358
    It's not a bug. You can't really use GetButtonDown in FixedUpdate, because it's only true for the one frame in which it occurs, and it's reasonably likely (depending on the framerate vs. the physics framerate) that FixedUpdate won't be executed during that particular frame.

    --Eric
     
  3. Iron-Warrior

    Iron-Warrior

    Joined:
    Nov 3, 2009
    Posts:
    639
    Oh. Good to know it's not a bug.

    After reading your response, I went out and learned about the differences between Update and FixedUpdate...so basically if I'm performing any kind of physics (like CharacterController.Move or AddForce) I should use FixedUpdate, but for anything else I use Update?

    Thanks for the quick response...and just looked at your post count...and it's over 9000! You are one helpful guy Eric, seriously, half my questions I ask are answered by you!
     
  4. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    31,358
    Yep. Unfortunately somebody already beat you to the "over 9000" thing in another topic. ;)

    --Eric