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
2
Question by I_CAST_FIST · Jun 04, 2015 at 02:01 PM · androidguitoucheventsystemgui-button

Android Buttons Responding Poorly To Touch Controls

I'm using the new GUI system in version 5.0.2f of Unity and I've become rather stumped during my testing on my android device; If i tap my buttons and IMMEDIATELY lift my finger off them, they work perfectly as intended. However if i hold my finger on any of the buttons for more than a fraction of a second they rapidly switch between their pressed, highlighted and normal states and seemingly randomly land on one and stick with it. What's causing this and how do i stop it?

alt text

I've tried;

  • Changing the Input Actions per second to 1 rather 10 in the EventSystem

  • Changing the Drag Threshold to well over values of 100 far from its default setting

  • Removing all script functionality from the buttons, reducing them to just Sprite Swap buttons

  • Changing the Button Navigation Settings to None rather than automatic

Here's my setup for the event system, hierarchy and menu design(early design):

alt text

I've established it isn't a hardware issue with the SM-T210 tablet, would there be a way for me to write a script that forces the state of the button to remain on clicked for a number of seconds and ignore all other input on that particular button, or another workaround?

If it's worth mentioning it's a 2D game, thankyou in advance for reading or contributing, I've managed to avoid having to ask any questions for the duration of the project but I'm rather stuck for ideas here and can't find anyone else who encountered the problem and resolved it.

q1.png (320.2 kB)
q3.png (32.0 kB)
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
1
Best Answer

Answer by I_CAST_FIST · Jun 17, 2015 at 03:21 AM

Managed to fix it myself after going off and finishing off a dialogue system, FOR ANYONE ELSE EXPERIENCING SIMILAR ISSUES WITH OVERLY RESPONSIVE OR TWITCHY BUTTONS FOR TOUCH SCREENS LIKE ANDROID AND IOS-

I made a new C# script and attached it to an object that i could put as a trigger OnClick for the buttons in question in the inspector with the following-

 using UnityEngine;
 using UnityEngine.UI;
 using System.Collections;
 
 public class DelayPress : MonoBehaviour 
 {
     public Button thisButton;
     
     public void DoTheThing()
     {
         StartCoroutine(DelayState());
     }
     
     private IEnumerator DelayState()
     {
             thisButton.interactable = false; 
             yield return StartCoroutine(UnscaledTimeUtil.WaitForRealSeconds(1));
             thisButton.interactable = true; 
             Debug.Log("coroutine complete");
     }
 }

Because my menu pauses the game by setting the time scale to 0 i couldn't use "yield return new WaitForSeconds(5);" because the coroutine won't work outside of scaled time. So i found a post here by matthiassoeholm and created an unscaled time utility for the coroutine to work from i called UnscaledTimeUtil, this is his utility code that also works just fine;

  public static class CoroutineUtil
  {
      public static IEnumerator WaitForRealSeconds(float time)
      {
          float start = Time.realtimeSinceStartup;
          while (Time.realtimeSinceStartup < start + time)
          {
              yield return null;
          }
      }
  }

WHAT THIS DOES - Is it allows you to temporarily disable any extra "presses" or clicks on whatever button you use the function in by an amount of time stored in a float, in my case 1 (1f) second. It functions perfectly for menu navigation because no one will be spamming those buttons for any good reason. Here's what it looks like in the inspector, just make sure to attach your DelayPress Script to a gameobject in your scene so you can drag it onto your new OnClick Function and to add your button in question to the button field in that script on the object-

alt text

alt text


inspector.png (5.8 kB)
buttonnnnn.png (16.6 kB)
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 cjsawyer · Aug 26, 2016 at 09:57 PM 1
Share

THAN$$anonymous$$ YOU. I don't know how this issue isn't more common. I've run into it on every Android device I've tried.

avatar image
0

Answer by Meltdown · Jun 17, 2015 at 03:28 AM

I've never had issues. But the way I handle button click/touch input is as follows...

  1. Add a field for your script in the Inspector for the button...

[SerializeField] private Button _myButton;

  1. Drag the button to this field on your script to assign it

  2. In your Start() method, wire up your button event handler...

_myButton.onClick.AddListener(OnMyButtonClicked);

  1. In your OnDestroy() method, wire up your remove listener event

    _myButton.onClick.RemoveListener(OnMyButtonClicked);

  2. Create a method to handle the button click...

      void OnMyButtonClicked()
         {
               Debug.Log("My button was pressed!");
         }
    
    
    
    
    
    
    
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 I_CAST_FIST · Jun 17, 2015 at 08:06 PM 0
Share

Unfortunately if the button in question still has a button component in the inspector it still rapidly switches between states even when using a listener, thankyou for the answer though :)

Curiously the legacy gui methods dont cause this issue, but im having trouble reproducing it outside this project :s

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Android - touch input causes black screen (except GUI) 1 Answer

Why this simple code doesnt work? 0 Answers

Main menu touch input for android 1 Answer

Is there a way to toggle between active characters via a GUI? 0 Answers

Touches aren't working on Android 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