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.

Question Change Interaction layer Mask With Code

Discussion in 'VR' started by Matekoty, Dec 20, 2021.

  1. Matekoty

    Matekoty

    Joined:
    Apr 12, 2020
    Posts:
    8
    Is there any way to Change Interaction layer Mask With Code?
     
  2. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    3,437
  3. Matekoty

    Matekoty

    Joined:
    Apr 12, 2020
    Posts:
    8

    Yeah... I understand this, but how can I modify the Interaction layer Mask from another code? How can I call it?
    Sure,
    "Interaction layer Mask" = myLayer;
    but I can't refer to it.
     
  4. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    3,437
    Wdym from another code?
     
  5. Matekoty

    Matekoty

    Joined:
    Apr 12, 2020
    Posts:
    8
    I mean from another script. I have a pre-made XRGrabInteractable script by XR Interaction Toolkit, and I want to change the Interaction Layer mask variable in this script by my own script. But I don't know how to refer to this variable.
     
  6. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    3,437
  7. Matekoty

    Matekoty

    Joined:
    Apr 12, 2020
    Posts:
    8
  8. Matekoty

    Matekoty

    Joined:
    Apr 12, 2020
    Posts:
    8
  9. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    3,437
    GetComponent<Grabbable>.InteractionLayerMask = MyLayer

    If it's private just make it public
     
  10. Matekoty

    Matekoty

    Joined:
    Apr 12, 2020
    Posts:
    8
    Yes! That is the solution that I'm looking for, but if I write this script, nothing happen.

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.XR.Interaction.Toolkit;
    public class LayerChange : MonoBehaviour
    {
    public LayerMask RightHand;
    void Update()
    {
    GetComponent<XRBaseInteractable>().interactionLayerMask = RightHand;
    }
    }

     
  11. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    3,437
    Doesn't it update in the inspector as well?
    If so, does the code even run?
     
  12. Matekoty

    Matekoty

    Joined:
    Apr 12, 2020
    Posts:
    8
    Yes! If I build in a Debug.Log function, it works.
     
  13. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    3,437
    What do you mean with the last part?
    And if it works there it should just work. Otherwise I cannot help much
     
  14. RhinocerosGamesProduction

    RhinocerosGamesProduction

    Joined:
    Dec 19, 2017
    Posts:
    4
    You should try something like this:

    interactableObject.interactionLayers = InteractionLayerMask.GetMask("Default");


    Where the interactableObject must implement the IXRInteractable interface, so for example be of type XRBaseInteractable which implements that interface by default.
    The parameter(s) in GetMask are defined interaction layers.
    But keep in mind: those interaction layers from the XR Interaction Toolkit are different from normal layers, so don't mix them up!
     
    etaysch99 and BalticCortex like this.
  15. seligc

    seligc

    Joined:
    Dec 10, 2015
    Posts:
    10
    Thank you so much. Spent all yesterday evening puzzling over this. Kept ending up with the traditional Layers information. It worked a treat! Just come back to it this evening and it worked.