Welcome to the Oculus Developer Forums!

Your participation on the forum is subject to the Oculus Code of Conduct.

In general, please be respectful and kind. If you violate the Oculus Code of Conduct, your access to the developer forums may be revoked at the discretion of Oculus staff.

[SOLVED] Click events fired twice on Gear VR

tomazvovktomazvovk Posts: 61
Hiro Protagonist
edited March 2017 in Unity Development
Hello, I am having a strange problem since the latest Oculus/GearVR update (not sure which one it was :blush: ). When I click on a button in Editor it works as expected, same when running the app in dev mode on the phone. But when I put the phone into Gear VR, clicks/taps are executed twice. I tried debugging via Wi-Fi and adb printed debug text from the same function twice (looks like in different frames though). I am using OVRCameraRig, GazePointerRing (from sample framework) and OVRInputModule. Buttons are standard ones from Unity's UI.

I have two apps with this problem. One is made in Unity 5.4.2f2 (Oculus Utilities v1.9.0, OVRPlugin v1.8.0) and another in Unity 5.5.0f3 (Oculus Utilities v1.10.0, OVRPlugin v1.10.0).

I tried to run older version of the app made in Unity 5.4.2f2 and it has the same porblem. I know that it worked before.

Here is additional information on GearVR/Oculus software installed on the phone:

Samsung Galaxy S6, Android 6.0.1

Gear VR Service 2.6.41
Gear VR SetupWizard 2.3.20
Gear VR Shell 2.3.02
Gear VR System 1.1.05

Oculus 2.26.7
Oculus System Activities 1.11.0-45918658
Oculus System Driver 1.0.4.2-45411680

You can see the OVRInputModule settings in the image below. "Invert Swipe Y Axis" setting was added by me but it doesn't affect clicks. Any help appreciated!


Comments

  • tomazvovktomazvovk Posts: 61
    Hiro Protagonist
    edited December 2016
    I just wanted to add, that I created a new empty project in Unity 5.5.0f3 (Oculus Utilities v1.10.0, OVRPlugin v1.10.0). Same problem.

    When I take the phone from Gear VR I can see a notification about disconnected mouse. Is this normal?

    @imperativity
    Thanks, I'll be patient :)
  • vrdavebvrdaveb Posts: 1,596 Oculus Staff
    > when I put the phone into Gear VR, clicks/taps are executed twice.

    Are you using OVRInput in addition to OVRInputModule? If so, you may want to skip your OVRInput-based code when the active controller is the touchpad:

    if (OVRInput.GetActiveController() != OVRInput.Controller.Touchpad) { /* do input handling */ }
    We recently added touchpad support to OVRInput and without the above check, you may get your gamepad button handling logic firing at unexpected times in addition to the usual touchpad handling code.

    If you are really getting duplicate touchpad input, make sure you don't have two copies of components like OVRTouchpad or OVRInputModule in your scene.
  • tomazvovktomazvovk Posts: 61
    Hiro Protagonist
    edited January 2017
    @vrdaveb 
    I'm using OVRInputModule only. I added the following code to print active device to the console:
    Debug.Log(OVRInput.GetActiveController().ToString());
    First click prints None and immedeatelly after it prints Touchpad. Every click after that prints Touchpad twice. Checking if there are multiple copies of components mentioned above was the first thing I did.

    I made another empty project (Unity 5.5.0f3), imported Utilities 1.10 package and copied OVRHarness, OVRInspector and Parse folders from Oculus Sample Framework (1.5.1). I made an empty scene with OVRCameraRig, GazePointerRing and world space Canvas (with Graphic Raycaster disabled and OVRRaycaster enabled). EventSystem's standalone input module is disabled and OVRInputModule is enabled).

    I set up player settings for VR and clicks worked as they should. I noticed that I forgot to set Android API level (it was set to 9 - Android 2.3.1). As soon as I changed API level, clicks started to get called twice. I tried to change API back to 9 and it didn't work anymore. Then I cleared data and cache on the phone and installed the app again. Clicks started to work again. But I can't replicate this again. It worked only once, no matter how many times I change API or delete data/cache. Uninstalling and reinstalling also doesn't help.

    I updated Android SDK's, tools, platform tools, etc... It didn't help.
  • tomazvovktomazvovk Posts: 61
    Hiro Protagonist
    Hello, sorry for late reply. Yes, I still have this problem.
  • tomazvovktomazvovk Posts: 61
    Hiro Protagonist
    @imperativity
    Okay, good to know.Thank you again for helping out!
  • tomazvovktomazvovk Posts: 61
    Hiro Protagonist
    Confirming that the issue has been resolved using the latest Oculus Utilities (1.12).
  • teliportmeteliportme Posts: 1
    NerveGear
    I'm Having the same issue now after upgrading to 5.6.0f3 with both Oculus Utilities 1.12 and 1,13. 
  • Rogar303Rogar303 Posts: 5
    NerveGear
    I am having this issue as well in Unity 5.6.0f3, and Oculus Utilities 1.14. Regular UI Buttons are being clicked twice. All I have in my scene is the EventSystem with the OVRInputModule, a Canvas with the OVRRaycaster, and a Button in the canvas, and I can see that the button click is most often than not triggered twice. Might be worth noting that every time I swipe, instead of click in center of the Touchpad, the button click is triggered once. With that said, though, I don't expect a click when swiping so this is another issue I am having.
  • SerFreemanSerFreeman Posts: 2
    NerveGear
    I had the same problem. I don't know what is official solution but you can try mine which works in my case.
    Go to OVRInputModule.cs script and change this method.
    virtual protected PointerEventData.FramePressState GetGazeButtonState()
            {
                //var pressed = Input.GetKeyDown(gazeClickKey) || OVRInput.GetDown(joyPadClickButton);
                //var released = Input.GetKeyUp(gazeClickKey) || OVRInput.GetUp(joyPadClickButton);
    
    //#if UNITY_ANDROID && !UNITY_EDITOR
    //            // On Gear VR the mouse button events correspond to touch pad events. We only use these as gaze pointer clicks 
    //            // on Gear VR because on PC the mouse clicks are used for actual mouse pointer interactions.
    //            pressed |= Input.GetMouseButtonDown(0);
    //            released |= Input.GetMouseButtonUp(0);
    //#endif
                var pressed = Input.GetMouseButtonDown(0);
                var released = Input.GetMouseButtonUp(0);
    
                if (pressed && released)
                    return PointerEventData.FramePressState.PressedAndReleased;
                if (pressed)
                    return PointerEventData.FramePressState.Pressed;
                if (released)
                    return PointerEventData.FramePressState.Released;
                return PointerEventData.FramePressState.NotChanged;
            }

  • Rogar303Rogar303 Posts: 5
    NerveGear
    Hey SerFreeman, your solution works! Thank you very much!!! 

    I'm still having the issue where a swipe is registered as a click as well, but that issue I can work around on. 
  • summitgamessummitgames Posts: 2
    NerveGear
    I have developing this for almost one and a half year.. they update new things and bring more problems that worked perfectly fine.. Its the same problem i am facing gets clicked twice on gear vr and swipe gets registers as click.
  • Rogar303Rogar303 Posts: 5
    NerveGear
    This alternative solution allowed clicks and swipes to be independent, but with it OnDown and OnUp no longer worked: 
    var pressed = Input.GetKeyDown(gazeClickKey) || OVRInput.GetDown(joyPadClickButton);
    var released = Input.GetKeyUp(gazeClickKey) || OVRInput.GetUp(joyPadClickButton);
    
    if (pressed && released)
        return PointerEventData.FramePressState.PressedAndReleased;
    if (pressed)
        return PointerEventData.FramePressState.Pressed;
    if (released)
        return PointerEventData.FramePressState.Released;
    return PointerEventData.FramePressState.NotChanged;
    Just set the gazeClickKey to Keycode.Space.
  • BrainloginBrainlogin Posts: 57
    Hiro Protagonist
    I honestly didn't know how to turn imperativity's advise into a solution, how not to use Input because even the OVR Input Module itself uses Input such as Input.GetMouseButtonDown. But if this just meant that we should not have the StandaloneInputModule component on EventSystem, I did not have that, I only had OVR Input Module, yet I had the same problem with the Gear VR touch input double registered. The alternative solutions suggested above fixed this but they didn't work with other control devices. Here is my replacement for GetGazeButtonState() that gets rid of the double firing with built-in touchpad AND works with both Gear VR controller's trigger input and third party game pads X button:
    virtual protected PointerEventData.FramePressState GetGazeButtonState()
        {
            var pressed = Input.GetMouseButtonDown(0) || OVRInput.GetDown (OVRInput.RawButton.X, OVRInput.Controller.Active) || OVRInput.Get (OVRInput.Button.PrimaryIndexTrigger);

  • JBPrimeJBPrime Posts: 1
    NerveGear
    I also ran into this problem on Unity 2017.4.1f1 using the Oculus Integration package 1.24.0.  The OVRInputModule was giving me two button clicks when I ran with GearVR on a Galaxy S6.  It looked like it was getting the mouse button from Unity's Input, and then several frames later it got the touchpad controller button from OVRInput.  Doing some further tracing, I got this sequence of events in OVRInputModule.GetGazeButtonState():

    [Frame 50]: Input.GetMouseButtonDown() is true
    [Frame 55]: Input.GetMouseButtonUp() is true
    [Frame 56]: OVRInput.GetDown() is true
    [Frame 57]: OVRInput.GetUp() is true

    So I'd get a click event on frame 55 from the press/release sequence, and then another on frame 57 from the second press/release sequence.  Further digging and I noticed that OVRManager.Update() was running after Unity's EventSystem update on a given frame, which meant that OVRInputModule was processing input from OVRInput that hadn't been updated for the current frame.  So I changed the script execution order for OVRManager from -100 to -31122 (an arbitrarily large choice), and then OVRManager.Update() ran first, which pumped OVRInput.Update() and got all the button states correct for the frame before the Unity EventSystem updated.

    This meant that Input.GetMouseButtonUp() and OVRInput.GetDown() were true on the same frame, which by the OVRInputModule logic meant I got a click event on that frame, but it did not start a new event sequence, and the OVRInput.GetUp() on the next frame did not trigger a second click event.
Sign In or Register to comment.