Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

XRBaseInteractable override problems ?

Discussion in 'Scripting' started by steinbrecherandreas, Aug 26, 2020.

  1. steinbrecherandreas

    steinbrecherandreas

    Joined:
    Aug 19, 2020
    Posts:
    5
    I got a problem while following a VR tutorial series. its about climbing on a wall. He overrides the OnSelectEnter and Exit functions. but that isnt working right for me. it is working, but just one time. i couldnt find an answer, so i started playing around why i cant get it right. so i stripped it all down and made a test scene.

    i made a new project and installed the VR dependencies,
    I created a Plane as floor, a sphere and a new vr roomscale rig. this standard one with rayinteractors.
    the sphere has a rigidbody. it has a collider and i added this script to the sphere.

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.XR.Interaction.Toolkit;
    5.  
    6.  
    7. public class Test : XRBaseInteractable
    8. {
    9.     protected override void OnSelectEnter(XRBaseInteractor interactor)
    10.     {
    11.         base.OnSelectEnter(interactor);
    12.         Debug.Log("SELECT ENTER");
    13.     }
    14.  
    15.     protected override void OnSelectExit(XRBaseInteractor interactor)
    16.     {
    17.         base.OnSelectExit(interactor);
    18.         Debug.Log("SELECT EXIT");
    19.     }
    20. }
    so shouldnt that setup print "SELECT ENTER" and "SELECT EXIT" to console everytime i press and release the grip button while the rayinteractors point on the sphere? it doesnt for me. it just does it one time. and only for one hand. no matter if i start my test with grabbing with the left or with the right controller.
    so... When i use the grip i can SelectEnter it... when i release the grip, i SelectExit it. but thats all. i cant do it a second time.

    if i replace the Test script with a normal XRGrabInteractable, i can take the ball and throw it away as many times i want. so it does the job normally.

    if i use the interactable events for the sphere in the editor its working fine.

    also the haptic events OnSelectEnter and OnSelectExit for the rays are working. just that script does it not right;

    hopefully someone can help with that. i cant figure that out. is it a bug? :) the problem is, i finished this tutorial already a few days ago. at this point i didnt pay attention to this part, cause i did not have any problems there. but now i always run into this strange behavior. Is it a strange behavior? or is it something i am missing here? one little checkbox somewhere... i dont know :)

    THX in advance.
     
    Last edited: Aug 26, 2020
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,780
    First of all I want to applaud your instinct here. This is how to troubleshoot. Isolate the problem until that's all there is left.

    I also applaud you sticking Debug.Log() calls in there because that is how you find out that in this case, your code isn't even running. Definitely changes where you look for the solution!

    As for the problem, I am unfamiliar with those two delegates / callbacks. I imagine that the API specifies certain conditions under which they will be called, such as how the scene has to be set up, what features have to be enabled in the VR input subsystems, etc. I would start with the docs and carefully work through what they tell you, and I would also suggest perhaps reposting this over in the AR/XR/VR group, as that group might have a lot more immediate hands-on experience with this particular API.
     
  3. steinbrecherandreas

    steinbrecherandreas

    Joined:
    Aug 19, 2020
    Posts:
    5
  4. steinbrecherandreas

    steinbrecherandreas

    Joined:
    Aug 19, 2020
    Posts:
    5
    aaaarghs ... i found it. it did work all the time. i had the console output set to collabs. so i only saw these 2 events. i didnt see the timestamp change .... damn. a whole day lost for this... but now i have to find another problem why i cant finish that tutorial i was trying ..... *blush.