Search Unity

Question XR interaction toolkit - Selection Visualisation render problem

Discussion in 'AR' started by mikevandernoordt73, Apr 9, 2021.

  1. mikevandernoordt73

    mikevandernoordt73

    Joined:
    Apr 9, 2021
    Posts:
    6
    Hi there,
    I have been bashing my head against the wall oor quite a while now. I created a basic interactable setup (AR) basically taking the sample file as reference.
    Now my selection visualisation has a transparent standard material (just like the sample) but when tapping it, it very randomly seemed to select the placed object, but mostly not...

    After weeks and weeks of coming back to the scene, reordering stuff i finally saw what was happening:

    When tapping the object it seems not to activate the selection visualization cube, but when simply moving the device (iPhone) after tapping it becomes visible and is selected. I tried changing Custom render queue in debug mode but same thing keeps happening...

    Anyone had same issue and found a solution to this?
     
  2. danUnity

    danUnity

    Joined:
    Apr 28, 2015
    Posts:
    229
    I'm not sure I understand your issue exactly but how this works is the following:

    The Gesture Interactor that's placed on the Camera usually, is setting every AR interactables, that are visible by the camera, to Hovering mode.

    You can use the XR Interaction Debugger to see this. It's actually not the best the way this is implemented and sometimes you should be able to select a selectable and you can't since either it's positioned low under the camera or if the center of the game object on which the interactable is placed is outside the camera frustum.

    When an interactable is hovering, then it's possible for you to Select it by tapping on it when there's an AR Selection Interactable on it.

    Does that helps?
     
  3. mikevandernoordt73

    mikevandernoordt73

    Joined:
    Apr 9, 2021
    Posts:
    6
    thanks for your reply,
    You gave me at least a bit more insight. When the placed interactable is tapped, when small enough and centered in view, the visualizer is instantly visible, so it has to do with the center somehow.
    However when the object is slighly low in the camera's view i tap.... nothing happens.... i move the camera slightly... and pop! the visualizer appears... even after having the camera still for several seconds before moving my phone... the center of the interactable in this case is not dead center but still well within the frustum...

    So there's still something weird going on, I would expect when a raycast hits the boxcollider it would activate the visualizer no matter if the center or pivot is outside o the view, or even close to the edge...

    But thanks, i understand a bit more about the inner working ;)

    edit: I just ound out, when in landscape mode this "bug" doesn't occur, I hope this helps inding a solution. cheers
     
    Last edited: Apr 10, 2021
  4. danUnity

    danUnity

    Joined:
    Apr 28, 2015
    Posts:
    229
    Maybe the issue is less visible on landscape but it should still be there.

    To fix it, you need to make your own Gesture Interactor and edit the GetValidTargets(List<XBaseInteractable validTargets) function. That's what I did.
     
  5. mikevandernoordt73

    mikevandernoordt73

    Joined:
    Apr 9, 2021
    Posts:
    6
    Thanks and yeah you're right, the issue is stille there in landsacape as you described ;(
    Sorry i'm not a great programmer, I got as ar as finding the ARGestureInteractor.cs script and the function you mention. Should I edit the function in that particular script? I'm a bit lost on how and what to edit there. I hope you can give a bit o a a clue o_O

    cheers!

    (I guess this is the function?:)

    Code (CSharp):
    1.         public override void GetValidTargets(List<XRBaseInteractable> validTargets)
    2.         {
    3.             validTargets.Clear();
    4.  
    5.             var cameraBehaviour = Camera.main;
    6.             if (cameraBehaviour == null)
    7.                 return;
    8.  
    9.             var hFOV = GetHorizontalFOV(cameraBehaviour);
    10.  
    11.             foreach (var interactable in interactionManager.interactables)
    12.             {
    13.                 // We can always interact with placement interactables.
    14.                 if (interactable is ARPlacementInteractable)
    15.                     validTargets.Add(interactable);
    16.                 else if (interactable is ARBaseGestureInteractable)
    17.                 {
    18.                     // Check if angle off of camera's forward axis is less than hFOV (more or less in camera frustum).
    19.                     // Note: this does not take size of object into consideration.
    20.                     // Note: this will fall down when directly over/under object (we should also check for dot
    21.                     // product with up/down.
    22.                     var toTarget =
    23.                         Vector3.Normalize(interactable.transform.position - cameraBehaviour.transform.position);
    24.                     var dotForwardToTarget = Vector3.Dot(cameraBehaviour.transform.forward, toTarget);
    25.                     if (Mathf.Acos(dotForwardToTarget) < hFOV)
    26.                         validTargets.Add(interactable);
    27.                 }
    28.             }
    29.         }
     
  6. danUnity

    danUnity

    Joined:
    Apr 28, 2015
    Posts:
    229
    Hi,

    This function returns the list of interactables that are valid for the Gesture Interactor to interact with. When an interactable is valid, it will be shown as "Hover" to true.

    You could do the following to Hover every interactables which is not a perfect solution since it will "Hover" even interactables that are not shown on Camera but here it is:


    Code (CSharp):
    1. public override void GetValidTargets(List<XRBaseInteractable> validTargets)
    2.         {
    3.             validTargets.Clear();
    4.             var cameraBehaviour = Camera.main;
    5.             if (cameraBehaviour == null)
    6.                 return;
    7.             var hFOV = GetHorizontalFOV(cameraBehaviour);
    8.             foreach (var interactable in interactionManager.interactables)
    9.             {
    10.                 // We can always interact with placement interactables.
    11.                 if (interactable is ARPlacementInteractable)
    12.                     validTargets.Add(interactable);
    13.                 else if (interactable is ARBaseGestureInteractable)
    14.                 {
    15.                     validTargets.Add(interactable);
    16.                 }
    17.             }
    18.         }
     
  7. mikevandernoordt73

    mikevandernoordt73

    Joined:
    Apr 9, 2021
    Posts:
    6
    Thanks again sir!

    It seems I can't edit the script itself (it reverses to original version when trying to save).

    Anyway, I'm not not sure if it has to do with hover state being true or not: I believe the hover state is actually set to true after tap but the weird thing is when tapping it when the center is somewhat below the horizontal center of the screen the visualizer isn't turned to visible, but when moving my device down (so the center of the interactable moves above the horizontal centerline) the visualizer appears "spontaneously" and is draggable, moveable and rotatable (so it must have the hover state on true right?)

    Anyway maybe it's just hard too hard to explain in text and I have to make a video of what is actually happening.

    Thanks for trying to help anyway!
    cheers