Search Unity

Question XR Interaction Toolkit - Cannot grasp when XR Origin is instantiated

Discussion in 'XR Interaction Toolkit and Input' started by HirokiYamada, Mar 3, 2023.

  1. HirokiYamada

    HirokiYamada

    Joined:
    Jun 21, 2016
    Posts:
    5
    Hello.
    I modified the Demo scene in XR Interaction Toolkit 2.3.0 to disable "Complete XR Origin Set Up" and Instantiate it in the Start method and now I cannot grasp.
    Other functions, such as movement, seem to work fine.

    Is this normal behavior? Is there a workaround?

    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class XROriginInstantiator : MonoBehaviour
    4. {
    5.     public GameObject prefab;
    6.  
    7.     void Start()
    8.     {
    9.         Instantiate(prefab, new Vector3( 0.0f, 0.0f, 0.0f), Quaternion.identity);
    10.     }
    11. }
    12.  
    Specs:
    Unity: 2021.3.13f1
    XR Interaction Toolkit 2.3.0
    Meta Quest 2​
     

    Attached Files:

  2. VampireLestat

    VampireLestat

    Joined:
    Oct 15, 2016
    Posts:
    14
    Interesting, I wonder if that's the same problem that I just started seeing. Grabbing was working completely fine for me recently and one of the things I changed was to spawn my XR Rig at runtime instead of having it already in the scene. I double checked my XRDirectInteractors and the XRGrabInteractables and they all seem fine. In the XR Interaction Debugger, I can see that the masks are the same and I can see Select activating when I pull the grip, but Hover and Select never change on the Interactables. I'll try putting it back in the scene instead of spawning it and see if that fixes it.

    Update: Unfortunately, no. That didn't fix it for me, so may not be the same issue.
     
  3. VampireLestat

    VampireLestat

    Joined:
    Oct 15, 2016
    Posts:
    14
    I think I have figured out the issue here.

    There is an XRInteractionManager in the 'Complete XR Origin Set Up' prefab and there was in my Player prefab as well. When you have this prefab in the scene at startup, it gets used and all of the Interactors and Interactables are happy. When you don't have it in your scene at startup, the XRI system generates one and adds it to the scene for you (you can see the prefab instance in the scene after you hit Play). Now when your prefab gets spawned, there is a second XRInteractionManager and that causes the problems we were both seeing with being unable to hover or select items.

    The solution is to delete the XRInteractionManager from your prefab if you want to spawn it at runtime. The XRI system will create the XRInteractionManager for you in Awake and the Interactor and Interactable classes will get a reference to it through FindObjectOfType. Once I did this, I could spawn my player and pick up items whether they were in my current scene, spawned at runtime, or in an additive scene.

    Unity XRI team: if you are reading this, I think you should remove the XRInteractionManager from your prefabs and instruct users to let the system create and get references to this automatically.
     
    LizhengheChen and HirokiYamada like this.
  4. ericprovencher

    ericprovencher

    Unity Technologies

    Joined:
    Dec 17, 2020
    Posts:
    267
    Appreciate your searching here @VampireLestat. I brought this up to the team to figure out what the best course of action is.
     
    VampireLestat likes this.
  5. Qleenie

    Qleenie

    Joined:
    Jan 27, 2019
    Posts:
    868
    For me the problem occurs also with only having one XRInteractionManager, I can't figure out a workaround. Once I disable and re-enable XR, using sliders does not work anymore (you can still click slider, but not drag anymore).
    I don't see any additional XRInteractionManager getting spawned.
     
  6. ericprovencher

    ericprovencher

    Unity Technologies

    Joined:
    Dec 17, 2020
    Posts:
    267
    I think that’s a separate issue related to the xr input module. I’m wondering if you have duplicate input modules in your scene or not.
     
  7. Qleenie

    Qleenie

    Joined:
    Jan 27, 2019
    Posts:
    868
  8. ericprovencher

    ericprovencher

    Unity Technologies

    Joined:
    Dec 17, 2020
    Posts:
    267
    Cheers yeah. I’ll look into this problem.
     
    Qleenie likes this.
  9. HirokiYamada

    HirokiYamada

    Joined:
    Jun 21, 2016
    Posts:
    5
    @VampireLestat Thanks for the advice!
    I removed XRInteractionManager from the prefab and the grasp function works.
     
    VampireLestat likes this.
  10. kmilo9999

    kmilo9999

    Joined:
    Oct 20, 2016
    Posts:
    3
    Im another developer with the same issue, and I can confirm deleting the XRInteractionManager from the prefab works. I am using XR interaction toolkit 2.2.0
     
  11. VRDave_Unity

    VRDave_Unity

    Unity Technologies

    Joined:
    Nov 19, 2021
    Posts:
    275
    Hey all,
    I will talk to the team about removing the Interaction Manager from the prefab so interactions don't get mangled when instantiating the prefab separately.

    Alternatively, we can also look into adding a flag to the Interaction Manager to behave more like a singleton, handing off any registered interactors/interactables to a single instance and disabling itself if there is an existing manager in the scene. Thank you all for the feedback on this! :)
     
    HirokiYamada and VampireLestat like this.
  12. lloydsummers

    lloydsummers

    Joined:
    May 17, 2013
    Posts:
    359
    We should be able to stop it from auto-generating the Event System, and the XR Interaction Manager. We use WebGL/Desktop/VR/AR/etc in the same scene, and having no control over their creation breaks interactions throughout our projects.

    As a developer, I should be able to control what managers and event systems are being added to our scenes without needing to modify the XR Interaction Toolkit.