Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question XRController ControllerState - Sending interaction events every frame

Discussion in 'XR Interaction Toolkit and Input' started by KingKRoecks, Feb 1, 2021.

  1. KingKRoecks

    KingKRoecks

    Joined:
    Jul 28, 2013
    Posts:
    155
    In order to make the XRController class able to interact with UI, I've created an overriding class for the XRController that just looks at the SteamVR_Action_Boolean value to populate the XRControllerState for the "activated", "selected", and "uiPress" interaction states.

    here's what the XRController does:
    https://hatebin.com/bcbzjwgafo

    and here's what my overloaded controller does:
    https://hatebin.com/qwaqtrtlib

    As you can see, they're practically identical, I just change where the state data comes from.

    With the logging I've added, I can clearly see the "PressDown" and "PressUp" events happening at the right times, indicating that I'm not getting a PressDown every frame.

    Despite that, when I set these values to true for a "PressDown", they continue to send interaction events to objects under the cursor every frame until a "PressUp" occurs.

    Since the actual logic that fires off this event appears to be hidden, I can't see why this even is being propagated.

    UnityEngine.XR.Interaction.Toolkit.XRInteractionManager:Update () (at Library/PackageCache/com.unity.xr.interaction.toolkit@1.0.0-pre.2/Runtime/Interaction/XRInteractionManager.cs:148)

    Does anyone know how to fix this such that an even will only be sent off once? My UI will thank you

    upload_2021-2-1_9-29-40.png
     
  2. KingKRoecks

    KingKRoecks

    Joined:
    Jul 28, 2013
    Posts:
    155
    Looks like it has to do with the "wasActivatedThisFrame" boolean.

    If I call the "controllerState.ResetFrameDependentStates()" method, this value clears but then I never get an activate event.

    If I never clear it, then I never get an activate event.

    So it looks like there's a race condition where I'm setting the activate event, but it doesn't go off in the same frame as setting it because it's likely dependent on another thing.

    If I switch to the OnSelect on the SimpleInteractable instead of the OnActivate, it works.
     
  3. gogemx

    gogemx

    Joined:
    May 1, 2014
    Posts:
    2
    Have a look at XRControllerState class. It's simulating the press down and press up events.
    * clear all time dependent data with ResetFrameDependentStates().
    * get the activatedThisFrame / deactivateThisFrame flags according to a state change (button is pressed now, but wasn't pressed last frame and vice versa).

    I made a vr recorder class to actually capture the xr controllers and the three inputs (activate, select, and ui) with exactly the same logic and it works.

    although it would be a better solution to directly simulate Unity's input action instead of doing this awkward interaction state.

    at the moment i try to figure out how to do this, because there are so more input actions on a controller than only activate, select, and ui...