docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class InteractionGroupUnregisteredEventArgs

    Event data associated with the event when an Interaction Group is unregistered from an XRInteractionManager.

    Inheritance
    object
    BaseRegistrationEventArgs
    InteractionGroupUnregisteredEventArgs
    Inherited Members
    BaseRegistrationEventArgs.manager
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: UnityEngine.XR.Interaction.Toolkit
    Assembly: Unity.XR.Interaction.Toolkit.dll
    Syntax
    public class InteractionGroupUnregisteredEventArgs : BaseRegistrationEventArgs
    Remarks

    When an IXRInteractionGroup is unregistered with the XRInteractionManager, the unregistered event and interactableUnregistered events are invoked with InteractionGroupUnregisteredEventArgs as parameters.

    InteractionGroupUnregisteredEventArgs provides the unregistering interactionGroupObject and the XRInteractionManager associated with the unregistration event.

    Examples

    The following example subscribes to the interactionGroupUnregistered event and implements custom callback functions that will be called when the interactionGroupUnregistered is invoked. Enabling the "Example Interaction Group" game object will trigger the registered callback, while disabling it will trigger the unregistered callback.

    using UnityEngine;
    using UnityEngine.XR.Interaction.Toolkit;
    using UnityEngine.XR.Interaction.Toolkit.Interactables;
    using UnityEngine.XR.Interaction.Toolkit.Interactors;
    

    /// <summary> /// This class is an example script that registration events and demonstrates how to create callbacks for each event. /// </summary> class XRInteractionManagerRegistrationEventsSample : MonoBehaviour { [SerializeField] XRInteractionManager m_InteractionManager;

    XRInteractionGroup m_ExampleInteractionGroup;
    NearFarInteractor m_ExampleInteractor;
    XRGrabInteractable m_ExampleInteractable;
    
    void Awake()
    {
        // Try to find an interaction manager if necessary.
        // In Unity versions older than 2021.3.18f1, replace FindFirstObjectByType with FindObjectOfType.
        if (m_InteractionManager == null)
            m_InteractionManager = FindFirstObjectByType<XRInteractionManager>();
    
        // Note, the code below is creating the XRInteractionGroup, NearFarInteractor, and XRGrabInteractable before subscribing
        // to the interaction manager register/unregister events. Therefore, the initial register callback will not be logged.
        // To demonstrate these callbacks, enable/disable each example game object in the hierarchy to receive the register/unregister callbacks.
    
        // XRInteractionGroup automatically registers with the interaction manager on Awake
        var interactionGroupGO = new GameObject("Example Interaction Group");
        m_ExampleInteractionGroup = interactionGroupGO.AddComponent<XRInteractionGroup>();
    
        // XRBaseInteractor automatically registers with the interaction manager on Enable
        var interactorGO = new GameObject("Example Interactor");
        m_ExampleInteractor = interactorGO.AddComponent<NearFarInteractor>();
    
        // XRBaseInteractable automatically registers with the interaction manager on Enable
        var interactableGO = new GameObject("Example Interactable");
        m_ExampleInteractable = interactableGO.AddComponent<XRGrabInteractable>();
    }
    
    void OnEnable()
    {
        if (m_InteractionManager == null)
        {
            Debug.LogWarning("Interaction manager is null. No registration events will be executed in this example. Ensure there is an " + typeof(XRInteractionManager) + " in the scene.", this);
            return;
        }
    
        // Subscribe to the interaction manager registration events
        m_InteractionManager.interactionGroupRegistered += OnInteractionGroupRegistered;
        m_InteractionManager.interactorRegistered += OnInteractorRegistered;
        m_InteractionManager.interactableRegistered += OnInteractableRegistered;
    
        m_InteractionManager.interactionGroupUnregistered += OnInteractionGroupUnregistered;
        m_InteractionManager.interactorUnregistered += OnInteractorUnregistered;
        m_InteractionManager.interactableUnregistered += OnInteractableUnregistered;
    }
    
    void OnDisable()
    {
        if (m_InteractionManager == null)
            return;
    
        // Unsubscribe to the interaction manager registration events
        m_InteractionManager.interactionGroupRegistered -= OnInteractionGroupRegistered;
        m_InteractionManager.interactorRegistered -= OnInteractorRegistered;
        m_InteractionManager.interactableRegistered -= OnInteractableRegistered;
    
        m_InteractionManager.interactionGroupUnregistered -= OnInteractionGroupUnregistered;
        m_InteractionManager.interactorUnregistered -= OnInteractorUnregistered;
        m_InteractionManager.interactableUnregistered -= OnInteractableUnregistered;
    }
    
    void OnInteractionGroupRegistered(InteractionGroupRegisteredEventArgs args)
    {
        // Example of casting args object to interaction group base class
        var interactionGroup = args.interactionGroupObject as XRInteractionGroup;
    
        // Logic for interaction group registered event goes here
        if (interactionGroup != null && interactionGroup == m_ExampleInteractionGroup)
            Debug.Log(interactionGroup.transform.name + " is registered with " + args.manager.transform.name, this);
    }
    
    void OnInteractionGroupUnregistered(InteractionGroupUnregisteredEventArgs args)
    {
        // Example of casting args object to interaction group base class
        var interactionGroup = args.interactionGroupObject as XRInteractionGroup;
    
        // Logic for interaction group unregistered event goes here
        if (interactionGroup != null && interactionGroup == m_ExampleInteractionGroup)
            Debug.Log(interactionGroup.transform.name + " is unregistered with " + args.manager.transform.name, this);
    }
    
    void OnInteractorRegistered(InteractorRegisteredEventArgs args)
    {
        // Example of casting args objects to interactor base class
        var interactor = args.interactorObject as XRBaseInteractor;
    
        // Logic for interactor registered event goes here
        if (interactor != null && interactor == m_ExampleInteractor)
            Debug.Log(args.interactorObject.transform.name + " is registered with " + args.manager.transform.name, this);
    }
    
    void OnInteractorUnregistered(InteractorUnregisteredEventArgs args)
    {
        // Example of casting args objects to interactor base class
        var interactor = args.interactorObject as XRBaseInteractor;
    
        // Logic for interactor unregistered event goes here
        if (interactor != null && interactor == m_ExampleInteractor)
            Debug.Log(args.interactorObject.transform.name + " is unregistered with " + args.manager.transform.name, this);
    }
    
    void OnInteractableRegistered(InteractableRegisteredEventArgs args)
    {
        // Example of casting args objects to interactable base class
        var interactable = args.interactableObject as XRBaseInteractable;
    
        // Logic for interactable registered event goes here
        if (interactable != null && interactable == m_ExampleInteractable)
            Debug.Log(args.interactableObject.transform.name + " is registered with " + args.manager.transform.name, this);
    }
    
    void OnInteractableUnregistered(InteractableUnregisteredEventArgs args)
    {
        // Example of casting args objects to interactable base class
        var interactable = args.interactableObject as XRBaseInteractable;
    
        // Logic for interactable unregistered event goes here
        if (interactable != null && interactable == m_ExampleInteractable)
            Debug.Log(args.interactableObject.transform.name + " is unregistered with " + args.manager.transform.name, this);
    }
    

    }

    Properties

    interactionGroupObject

    The Interaction Group that was unregistered.

    Declaration
    public IXRInteractionGroup interactionGroupObject { get; set; }
    Property Value
    Type Description
    IXRInteractionGroup
    See Also
    IXRInteractionGroup
    XRInteractionGroup
    XRInteractionManager

    See Also

    IXRInteractionGroup
    XRInteractionGroup
    XRInteractionManager
    In This Article
    Back to top
    Copyright © 2025 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)