Unity-Technologies / XR-Interaction-Toolkit-Examples

This repository contains various examples to use with the XR Interaction Toolkit
Other
1.1k stars 360 forks source link

XRInteractionManager.ForceSelect does not work properly #51

Open rubit0 opened 3 years ago

rubit0 commented 3 years ago

I'm developing a AR application (using ARGestureInteractor in scene) and I'm using the XR Toolkit in version 1.0.0-pre.1 with Unity 2019.4 LTS.

In my use case I need to select an object via a UI Button click and not by directly tapping the object, for this I'm using XRInteractionManager.ForceSelect. But when using XRInteractionManager.ForceSelect I can see that the ARSelectionInteractable selected flag is set true and also the event ARSelectionInteractable.onSelectEntered is invoked, but the selectionVisualization does not get activated and furthermore the gestures for moving, scaling and rotation also do not work.

Doing a physical finger tap on the object works, but that is not what I need in my scenario.

Jotamaza commented 3 years ago

Same here with version 1.0.0-pre.3.

The interactable gets selected for a moment, and immediately deselected. Using the ForceSelect method is what XRIT uses when you fill the "Starting Selected Interactable" field for any interactor, so I suppose this is the correct way to achieve it.

I have obtained the same result with interactor.StartManualInteraction.

Is it a bug or we are using the wrong method?

Drumsmasher17 commented 3 years ago

Same here. Both interactionManager.ForceSelect and StartManualInteraction don't seem to work as one would hope.

richardmuthwill commented 3 years ago

Working in 1.0.0-pre.5

Using a simple debug script if anyone is looking for one:

using UnityEngine;
using UnityEngine.XR.Interaction.Toolkit;

public class XRSocketConnector : MonoBehaviour
{
    public XRSocketInteractor socket;
    public XRBaseInteractable interactor;
    public XRInteractionManager im;

    void Start()
    {
        // Both of these work in 1.0.0-pre.5
        socket.StartManualInteraction(interactor);
        // im.ForceSelect(socket, interactor);
    }
}
rubit0 commented 2 years ago

Version 1.0.0-pre.8 and Version 1.0.0-pre.5

I can not verify that. Invoking StartManualInteraction or ForceSelect only works for a single frame, after that XRInteractionManager will internally call ClearInteractorSelection -> SelectExit.

// Edit

With some debugging the code that is causing the issue in XRInteractionManager:

using (s_EvaluateInvalidSelectionsMarker.Auto())
    ClearInteractorSelection(interactor);

This leads to some native code which I can't further debug.

//Edit2 I had a wrong lead, it is in ClearInteractorSelection where interactor.selectTarget.IsSelectableBy(interactor) evaluates to false.

rubit0 commented 2 years ago

Alright I found the problem and the solution.

In ARSelectionInteractable the IsSelectableBy() method always returns false if it was not selected by a gesture, this of course works against ForceSelect and sabotages it.

So to fix this create a derived class from ARSelectionInteractable and override IsSelectableBy and remove the check. Like this:

public class ARSelectionInteractableFixed : ARSelectionInteractable
{
    public override bool IsSelectableBy(XRBaseInteractor interactor)
    {
        return interactor is ARGestureInteractor;
    }
}