Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 deltron1830 · Feb 27, 2017 at 01:38 AM · androiduibuttonscroll view

5.5.1f1 new UI system: Button in scrollview is not working on Android.

It works perfectly in the editor, but on Android it only sometimes registers an OnClick when I press it with my finger.

I'm on Unity 5.5.1f1

Is this a known issue? I'll post some videos of it if no-one has seen this before.

The scrollview is based on the default one from the Create\UI\scrollview menu Ive added a vertical layout group to it, to which I add prefabs that contain buttons. These are the buttons that are not working. The canvas is in front of the camera in worldspace and is scaled down to 0.02 in X and Y

VVVVVVVVVVV UPDATE VVVVVVVVVVVVV

I wrote my own workaround using 2D colliders instead of buttons The colliders are registering hits just fine. But when I wrote a class to not register hits if the scrollview moves, I get similar behaviour! Heres the crude little workaround class I wrote..

 public class ScrollButton : MonoBehaviour
 {
     public StoreItem Item;
 
     bool FingerDownOnMe;
 
     public void BeOnClicked()
     {
         VisualDebuggerRef.SetTxt("a store button" + " " + Random.Range(0, 10000));
         FingerDownOnMe = true;
     }
 
     // This is called on all these objects whenever the scrollview moves
     public void ScrollviewMoved()
     {
         FingerDownOnMe = false;
     }
 
     void Update()
     {
         // 'UppedthisFrame' will be true whenever any touchs phase == TouchPhase.Ended 
         if (Refs.man.Clickdetect.UppedthisFrame && FingerDownOnMe)
         {
             FingerDownOnMe = false;
             Item.ButtonHit();
         } 
     }
 }

I'm guessing Unities UI classes work in a somewhat similar way to my workaround one. The problem is that the scrollview is registering as being moved when it should not be. This may be because of my test device which is an S7. Maybe the touch resolution is so high it is registering movement that is smaller than one pixel??

Also maybe the fact the the entire canvas has been scaled down could be affecting this? Say Unities classes have a distance threshold, if they are not taking into account scale then working on a scaled down canvas might make the distances they are using too big, so the threshold is reached too easily

Im going to add a distance limit to my workaround...

VVVVVVVVVVVVV UPDATE2 VVVVVVVVVVVVVVVV

This workaround code using colliders works perfectly..

 public class ScrollButton : MonoBehaviour
 {
     const float scrollThreshold = 0.25f;
 
     public StoreItem Item;
 
     bool FingerDownOnMe;
     Vector3 HitPos;
 
     public void BeOnClicked()
     {
         //VisualDebuggerRef.SetTxt("a store button" + " " + Random.Range(0, 10000));
         FingerDownOnMe = true;
         HitPos = transform.position;
     }
 
     void Update()
     {
         // 'UppedthisFrame' will be true whenever any touchs phase == TouchPhase.Ended 
         if (Refs.man.Clickdetect.UppedthisFrame)
         {
             if (FingerDownOnMe && Mathf.Abs((transform.position - HitPos).y) < scrollThreshold) Item.ButtonHit();
 
             FingerDownOnMe = false;
         } 
     }
 }

I'm going to report this issue as a bug to Unity

Comment
Add comment · Show 4
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 aditya007 · Feb 27, 2017 at 04:44 AM 0
Share

The issue is most likely related to the prefabs, as they can't access gameObjects present in your hierarchy. If you've assigned the OnClick method from any of the Objects which are present in your hierarchy then the buttons won't work, as at RUNTI$$anonymous$$E, they will loose those reference to OnClick method.

avatar image aditya007 · Feb 27, 2017 at 10:49 AM 0
Share

What will be the reason of down vote, care to explain?

avatar image dakshesh1010 aditya007 · Feb 27, 2017 at 10:51 AM 0
Share

Who down voted whom?

avatar image aditya007 dakshesh1010 · Feb 27, 2017 at 12:15 PM 0
Share

The OP has down voted my comment and your answer without giving any reasons. I don't know what he has in $$anonymous$$d.

2 Replies

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

Answer by deltron1830 · Feb 27, 2017 at 09:44 PM

This is a bug in Unity. See my updates

ps. I have reported it

UPDATE.. from unity QA

" Hey,

We have been able to reproduce this bug and have sent it for resolution with our developers.

We highly appreciate your contribution. If you have further questions, feel free to contact us.

Regards, [Name removed] QA Team "

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
0

Answer by dakshesh1010 · Feb 27, 2017 at 06:20 AM

I did something similar once, instead of buttons as prefabs, I used entire panels (which had so may buttons and images and what not) as prefabs! And I just dragged those prefabs into different scenes.

@aaditya007 is indeed right there. You can use prefabs maybe, but you still have to refer to the method you need to call on OnClick(). If that doesn't work, just don't use prefabbed buttons. Instead make one, and duplicate the same to make new ones. I know it sounds dumb (or not so efficient), but the best practice in such cases (according to me) is to have a central method like a ButtonClickListener() in a Game Manager class, and resolve your button click from there so that you don't need to find the right script and object every time when you need a new button. You know you just need to call the ButtonClickListener() on every button, and that function in-turn resolves everything else!

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

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

153 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

Related Questions

UI button shows in editor but not on mobile? 0 Answers

Button with Animation disappear in Android build 0 Answers

UI works in editor, but not on mobile device 1 Answer

[5.4 - Unity2D - Android] UI Button Requires Child Text? 0 Answers

UI Button event triggers don't work on mobile but work in eaditor? 0 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