• 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 /
  • Help Room /
avatar image
0
Question by SangOk1994 · Sep 10, 2021 at 03:06 AM · errorinputmouseframe rate

Input.GetMouseButton error on low frame rapid input,Input.GetMouseButton error on LOW FRAME RAPIDINPUT

I made input getter component to use on UI

Code below seems to work fine but it makes error if LOW FRAME AND FAST REPEATED MOUSE CLICK

If mouse is double clicked rapidly, (making keydown->keyup->keydown->keyup in real mouse) functions are called in this sequence rarely.

     PcInputEnter()
     PcInputExit()
     PcInputEnter()
     and nothing happens

This is code I used.

 public class TouchTriggerKeyboardBinding : MonoBehaviour
 {
 #if UNITY_EDITOR || UNITY_STANDALONE || UNITY_STANDALONE_WIN // PC
     [SerializeField] private KeyCode keyCode;

     private TouchTrigger touchTrigger;
     private bool pressCach;

     private void Start()
     {
         touchTrigger = GetComponent<TouchTrigger>();
     }

     private bool CheckInput() => Cursor.lockState == CursorLockMode.Locked && Input.GetMouseButton(mouseIndex);

     private void Update()
     {
         bool pressNew = CheckInput();
         if (pressNew != pressCach)
         {
             pressCach = pressNew;

             if (pressNew)
                 touchTrigger.PcInputEnter();
             else
                 touchTrigger.PcInputExit();
         }
     }
 #endif
 }


This error is not easy to make, but it occurs once per 20 minutes in average, and our game is action game. this bug can not be ignored.

This error occurs many time on editor, more than 5 team member experienced this problem in editor mode play. (but hard to make occur again intentionally)

To make this error intentionally, recommended setting is like this.

  make editor slow. lower than 15frame/sec with many objects and [Scene] tab

we generate heavy object when mouse click, but this bug occurs without it too.

This is test code I made. if bug explained occur, [pressCach] will be true even you are not pressing mouse.

Any solution will be welcomed.

 public class GetButtonDownTest : MonoBehaviour
 {
     public int sum;
     public KeyCode keycode;
     public int mouseButtonIndex = 0;

     public bool pressCach = false;

     bool CheckInput()
     {
         if (keycode != KeyCode.None)
             return Input.GetKey(KeyCode.A);
         else
             return Input.GetMouseButton(mouseButtonIndex);
     }

     bool CheckDown()
     {
         if (keycode != KeyCode.None)
             return Input.GetKeyDown(KeyCode.A);
         else
             return Input.GetMouseButtonDown(mouseButtonIndex);
     }
     
     bool CheckUp()
     {
         if (keycode != KeyCode.None)
             return Input.GetKeyUp(KeyCode.A);
         else
             return Input.GetMouseButtonUp(mouseButtonIndex);
     }

     // Update is called once per frame
     void Update()
     {
         bool isPress = CheckInput();
         
         if(CheckDown())
             Debug.Log("Down" + keycode);
         if(CheckUp())
             Debug.Log("Up"+ keycode);
         
         if (pressCach != isPress)
         {
             pressCach = isPress;
             if (isPress)
             {
                 sum++;
                 Debug.Log("++"+ keycode);
             }
             else
             {
                 sum--;
                 Debug.Log("--"+ keycode);
             }
         }
     }
 },
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

0 Replies

· Add your reply
  • Sort: 

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

240 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 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 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

Mouse Input for Build Mode Windows are switched 0 Answers

Click to move with the new input system 1 Answer

New Input System: ArgumentException: Event must be a state or delta state event 3 Answers

Custom input not appearing in input manager 0 Answers

Detect mouse inputs when the scene is changing to another scene. 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