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 PlayerInput Lost XR Devices When Application Pause

Discussion in 'Input System' started by wenhao_unity, Jan 18, 2023.

  1. wenhao_unity

    wenhao_unity

    Joined:
    Nov 10, 2021
    Posts:
    2
    Background:
    ①I set "Run In Background" TRUE in "Player Setting".
    ②I use PlayerInput as input event sender, and implement input classification with control scheme.Weather set "Requirments & Devices List" in "Controller Scheme" does not affect the occurrence of the problem.(My XR device is Oculus Quest 2)
    upload_2023-1-18_16-44-55.png

    Problem:
    When I enter the scene, the device loads normally and the control scheme is correctly configured as shown in the code.I am also able to receive callbacks for input events normally.
    Code (CSharp):
    1. input.SwitchCurrentControlScheme("Oculus", InputSystem.devices.ToArray());
    upload_2023-1-18_16-47-24.png
    When I click on other applications to let Unity run to the background, because I use “Run In Backgournd”, "Game" triggers "Application Pause".When I go back to Unity Windows, application come back to normal,but I cannot get XR input callback anymore!
    When I returned to the Unity window, I noticed that there was no longer XR info in “Devices”.
    upload_2023-1-18_16-54-12.png

    Test:
    ①When the scene is just loaded, I manually configure “Scheme” through code, and load "Devices" at this time.
    So when in "Application Pause callback", I also reconfigure "Scheme" using a similar method. But this method didn't completely solve my problem.
    Code (CSharp):
    1. private void OnApplicationPause(bool pause)
    2.     {
    3.         if (!pause)
    4.         {
    5.             input.SwitchCurrentControlScheme("Oculus", InputSystem.devices.ToArray());
    6.         }
    7.     }
    ②I compared the input from the keyboard, even if the above configuration is exactly the same, it will not fail to receive the callback due to the reason of switching to the background.
    ③There is also a less relevant thing. Since the XR device may not be activated when the scene is loaded, a timing method is made. Only when the XR device is detected ,can the "Scheme" be set.
    upload_2023-1-18_17-12-21.png


    Thanks a lot!!!!
    BTW,is there any PlayerInput with XR tutorial. :):)
     
  2. wenhao_unity

    wenhao_unity

    Joined:
    Nov 10, 2021
    Posts:
    2
    :(:( Is there any tip about that...