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 [XR 2.3] Dragging slider with Ray Interactor & Poke doesn't work if initialize XR by script

Discussion in 'XR Interaction Toolkit and Input' started by Darkroll, Mar 8, 2023.

  1. Darkroll

    Darkroll

    Joined:
    Jul 29, 2017
    Posts:
    8
    Hi,

    I'm developing an application that can be configured for VR or PC (Mouse/Keyboard). To do so, I initialize XR by script (or not) following the configuration I choose.

    I'm using XR 2.3 and everything works properly if a check "Initialize XR on Startup". I'm able to drag my slider and use poke interaction. But since I want to do it by script, I have to uncheck it.

    Every other interaction works (Grab, UI etc..) except dragging the handle of a slider and pushing an UI button using poke interaction. I tried on the sample scene by checking or unchecking "Initialize XR on Starting" so I guess it's an issue somewhere with XR Initialization process.

    Did I miss something or the problem really comes from XR 2.3?

    Here is the code I use to initialize XR on Awake() :

    Code (CSharp):
    1.  
    2. void Awake()
    3.     {
    4.         LoadConfigFile();
    5.     }
    6.  
    7. public void LoadConfigFile()
    8.     {
    9. // Getting what config has been setup up
    10.  
    11. if (playerModeConfig == "VR")
    12.                 {
    13.                     isXR = true;
    14.                     StartCoroutine(StartXR());
    15.                 }
    16.                 else
    17.                 {
    18.                     isXR = false;
    19.                 }
    20.     }
    21.  
    22. public IEnumerator StartXR()
    23.     {
    24.         Debug.Log("Initializing XR...");
    25.         yield return XRGeneralSettings.Instance.Manager.InitializeLoader();
    26.  
    27.         if (XRGeneralSettings.Instance.Manager.activeLoader == null)
    28.         {
    29.             Debug.LogError("Initializing XR Failed. Directing to Normal Interaction Mode...!.");
    30.             StopXR();
    31.         }
    32.         else
    33.         {
    34.             Debug.Log("Initialization Finished.Starting XR Subsystems...");
    35.  
    36.             //Try to start all subsystems and check if they were all successfully started ( thus HMD prepared).
    37.             bool loaderSuccess = XRGeneralSettings.Instance.Manager.activeLoader.Start();
    38.             if (loaderSuccess)
    39.             {
    40.                 Debug.Log("All Subsystems Started!");
    41.             }
    42.             else
    43.             {
    44.                 Debug.LogError("Starting Subsystems Failed. Directing to Normal Interaction Mode...!");
    45.                 StopXR();
    46.             }
    47.         }
    48.     }
    49.  
    50.     public void StopXR()
    51.     {
    52.         Debug.Log("Stopping XR...");
    53.         XRGeneralSettings.Instance.Manager.StopSubsystems();
    54.         XRGeneralSettings.Instance.Manager.DeinitializeLoader();
    55.         Debug.Log("XR stopped completely.");
    56.     }
    Thanks !
     
  2. Qleenie

    Qleenie

    Joined:
    Jan 27, 2019
    Posts:
    851
    I can confirm that I have same issue; switching between XR and Desktop mode during running time breaks the dragging behavior of slider in XRI.
     
  3. Darkroll

    Darkroll

    Joined:
    Jul 29, 2017
    Posts:
    8
    Have you found any solution or workaround yet?
     
  4. Qleenie

    Qleenie

    Joined:
    Jan 27, 2019
    Posts:
    851
    Unfortunately not. Tried a few things, nothing worked so far.
     
  5. ericprovencher

    ericprovencher

    Unity Technologies

    Joined:
    Dec 17, 2020
    Posts:
    243
    Hey all I tested with your script in XRI 2.3.1 and I haven't been able to exactly repro the issue.

    With controllers, I'm testing the Hands Demo Scene and everything seems to work as expected. If you're running into some lazy init issues, I'm curious if you're waiting to initialize these game objects. If so that would probably explain why some UGUI elements don't work, as you probably have a non-XR input module being initialized.
    upload_2023-5-3_15-24-27.png

    That said, I did notice issues running hand tracking in the demo scene doing a lazy init. Looking into those problems.
     
    Qleenie likes this.
  6. Qleenie

    Qleenie

    Joined:
    Jan 27, 2019
    Posts:
    851
    I just checked with XRI 2.3.1 (former tests were on a older version) and can confirm that at least in my case the bug is gone!
     
  7. A_walk_in_the_park

    A_walk_in_the_park

    Joined:
    May 13, 2022
    Posts:
    3
    I also noticed there is problem with grabbing objects if you are using hand tracking. After you close a popup by pressing the button, it seems to disable the grabbing capabality on that hand. Anyone else had that issue?
     
  8. Darkroll

    Darkroll

    Joined:
    Jul 29, 2017
    Posts:
    8
    Thanks! I'm going to check with the last update and let you know

    I'm not using hand tracking in my case so I don't know