Search Unity

I have to make two small changes to XRInteractionManager.cs everytime I restart the project

Discussion in 'AR/VR (XR) Discussion' started by donnieholstrom, May 6, 2020.

  1. donnieholstrom

    donnieholstrom

    Joined:
    Dec 19, 2018
    Posts:
    3
    Hey guys,

    It's just a small problem, but there's probably a really simple explanation/fix. Every time I restart my project, I get the same compile errors, so I make the same two changes to the XRInteractionManager.cs script. I make these two functions public so one of my other scripts can access them:

    Code (CSharp):
    1.  
    2. public void SelectEnter(XRBaseInteractor interactor, XRBaseInteractable interactable)
    3. {
    4.     // If Exclusive Selection, is this the only interactor trying to interact?
    5.     if (interactor.requireSelectExclusive)
    6.     {
    7.         for (int i = 0; i < m_Interactors.Count; i++)
    8.         {
    9.             if (m_Interactors[i] != interactor
    10.                 && m_Interactors[i].selectTarget == interactable)
    11.             {
    12.                 return;
    13.             }
    14.         }
    15.     }
    16.     else
    17.     {
    18.         for (int i = 0; i < m_Interactors.Count; i++)
    19.         {
    20.             if (m_Interactors[i].selectTarget == interactable)
    21.                 SelectExit(m_Interactors[i], interactable);
    22.         }
    23.     }
    24.     interactor.OnSelectEnter(interactable);
    25.     interactable.OnSelectEnter(interactor);
    26. }
    27.  
    28. public void SelectExit(XRBaseInteractor interactor, XRBaseInteractable interactable)
    29. {
    30.     interactor.OnSelectExit(interactable);
    31.     interactable.OnSelectExit(interactor);
    32. }
    33.  
    What's causing this script to reset? Is it something I can prevent? Such a small thing, but as you can understand, quite an annoyance!

    Thanks everyone!
     
  2. joejo

    joejo

    Unity Technologies

    Joined:
    May 26, 2016
    Posts:
    958
    Packages are immutable. You may get away with editing it once by force, but on restart they will be reset.
     
  3. a436t4ataf

    a436t4ataf

    Joined:
    May 19, 2013
    Posts:
    1,933
    Until the Unity team updates XR (hopefully soon? :)) and removes all the unnecessarily private/internal methods, you need to use c# reflection to access them.

    This happens in your classes, not Unity's, so it'll continue working across all updates.

    Even better: use a static class extension, and you can effectively make the private method public, without touching Unity's source.

    e.g.: - UPDATE: I've written a short tutorial on this and added it to the FAQ. Direct link here: http://snapandplug.com/how-to-fix-unitys-private-vr-xr-code-so-it-becomes-public/
     
    Last edited: May 7, 2020
  4. donnieholstrom

    donnieholstrom

    Joined:
    Dec 19, 2018
    Posts:
    3
    I never thanked you, so thank you! This was really helpful :)
     
    a436t4ataf likes this.
  5. StayTalm_Unity

    StayTalm_Unity

    Unity Technologies

    Joined:
    May 3, 2017
    Posts:
    182
    You can also copy the package to a new location in your project or file system to avoid the overwriting.

    We use a cache on your machine to download XR.Interaction.Toolkit. This cache is occasionally updated, and will assume it's using an unmodified version of the package. This update will wipe over your changes.

    In order to break that overwriting link, you can copy the root package folder (in this case named XR.Interaction.Toolkit), and paste it into the [Root Project Folder]/Packages folder. This will cause *that* version to be included in your project, and that version won't suffer from overwrites. You can also paste that package elsewhere on your file system and use the Package Manager UI's Add From File option if you have multiple projects that need the same change.

    Then if you need to update the package to a newer version, you will need to update the cached version, then do a local merge between that and your local package.

    Does that all make sense?
     
    a436t4ataf likes this.