0
\$\begingroup\$

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

\$\endgroup\$
  • \$\begingroup\$ You shouldn't edit your question to add an answer. Write an answer to the question and edit that instead. \$\endgroup\$ – John Hamilton Feb 28 '17 at 11:24
  • \$\begingroup\$ I am using buttons in a scrollview on android with the same version of Unity you are using and my buttons work. I haven't tested on a S7 though, so who knows. \$\endgroup\$ – Tartle Wizard Feb 28 '17 at 17:50
0
\$\begingroup\$

This is a bug in Unity. (see more details on how I figured this out in question) I reported it. 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 "

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.