Class XRBaseInteractable
Abstract base class from which all interactable behaviours derive. This class hooks into the interaction system (via XRInteractionManager) and provides base virtual methods for handling hover and selection.
Namespace: UnityEngine.XR.Interaction.Toolkit
Syntax
public abstract class XRBaseInteractable : MonoBehaviour
Properties
activated
Gets or sets the event that is called when the selecting Interactor activates this Interactable.
Declaration
public ActivateEvent activated { get; set; }
Property Value
Type | Description |
---|---|
ActivateEvent |
Remarks
Not to be confused with activating or deactivating a
The ActivateEventArgs passed to each listener is only valid while the event is invoked,
do not hold a reference to it.
See Also
colliders
(Read Only) Colliders to use for interaction with this interactable (if empty, will use any child Colliders).
Declaration
public List<Collider> colliders { get; }
Property Value
Type | Description |
---|---|
List<Collider> |
customReticle
The reticle that will appear at the end of the line when it is valid.
Declaration
public GameObject customReticle { get; set; }
Property Value
Type | Description |
---|---|
GameObject |
deactivated
Gets or sets the event that is called when an Interactor deactivates this selected Interactable.
Declaration
public DeactivateEvent deactivated { get; set; }
Property Value
Type | Description |
---|---|
DeactivateEvent |
Remarks
Not to be confused with activating or deactivating a
The DeactivateEventArgs passed to each listener is only valid while the event is invoked,
do not hold a reference to it.
See Also
firstHoverEntered
Gets or sets the event that is called only when the first Interactor begins hovering over this Interactable as the sole hovering Interactor. Subsequent Interactors that begin hovering over this Interactable will not cause this event to be invoked as long as any others are still hovering.
Declaration
public HoverEnterEvent firstHoverEntered { get; set; }
Property Value
Type | Description |
---|---|
HoverEnterEvent |
Remarks
The HoverEnterEventArgs passed to each listener is only valid while the event is invoked, do not hold a reference to it.
See Also
hoverEntered
Gets or sets the event that is called when an Interactor begins hovering over this Interactable.
Declaration
public HoverEnterEvent hoverEntered { get; set; }
Property Value
Type | Description |
---|---|
HoverEnterEvent |
Remarks
The HoverEnterEventArgs passed to each listener is only valid while the event is invoked, do not hold a reference to it.
See Also
hoverExited
Gets or sets the event that is called when an Interactor ends hovering over this Interactable.
Declaration
public HoverExitEvent hoverExited { get; set; }
Property Value
Type | Description |
---|---|
HoverExitEvent |
Remarks
The HoverExitEventArgs passed to each listener is only valid while the event is invoked, do not hold a reference to it.
See Also
hoveringInteractors
(Read Only) The list of interactors that are hovering on this interactable.
Declaration
public List<XRBaseInteractor> hoveringInteractors { get; }
Property Value
Type | Description |
---|---|
List<XRBaseInteractor> |
See Also
interactionLayerMask
Allows interaction with Interactors whose Interaction Layer Mask overlaps with any layer in this Interaction Layer Mask.
Declaration
public LayerMask interactionLayerMask { get; set; }
Property Value
Type | Description |
---|---|
LayerMask |
See Also
interactionManager
The XRInteractionManager that this Interactable will communicate with (will find one if null).
Declaration
public XRInteractionManager interactionManager { get; set; }
Property Value
Type | Description |
---|---|
XRInteractionManager |
isHovered
(Read Only) Indicates whether this interactable is currently being hovered.
Declaration
public bool isHovered { get; }
Property Value
Type | Description |
---|---|
Boolean |
See Also
isSelected
(Read Only) Indicates whether this interactable is currently being selected.
Declaration
public bool isSelected { get; }
Property Value
Type | Description |
---|---|
Boolean |
See Also
lastHoverExited
Gets or sets the event that is called only when the last remaining hovering Interactor ends hovering over this Interactable.
Declaration
public HoverExitEvent lastHoverExited { get; set; }
Property Value
Type | Description |
---|---|
HoverExitEvent |
Remarks
The HoverExitEventArgs passed to each listener is only valid while the event is invoked, do not hold a reference to it.
See Also
onActivate
(Deprecated) Gets or sets the event that is called when an Interactor activates this selected Interactable.
Declaration
public XRInteractableEvent onActivate { get; set; }
Property Value
Type | Description |
---|---|
XRInteractableEvent |
onDeactivate
(Deprecated) Gets or sets the event that is called when an Interactor deactivates this selected Interactable.
Declaration
public XRInteractableEvent onDeactivate { get; set; }
Property Value
Type | Description |
---|---|
XRInteractableEvent |
onFirstHoverEnter
(Deprecated) Called only when the first Interactor begins hovering over this Interactable.
Declaration
public XRInteractableEvent onFirstHoverEnter { get; }
Property Value
Type | Description |
---|---|
XRInteractableEvent |
onFirstHoverEntered
(Deprecated) Gets or sets the event that is called only when the first Interactor begins hovering over this Interactable as the sole hovering Interactor. Subsequent Interactors that begin hovering over this Interactable will not cause this event to be invoked as long as any others are still hovering.
Declaration
public XRInteractableEvent onFirstHoverEntered { get; set; }
Property Value
Type | Description |
---|---|
XRInteractableEvent |
onHoverEnter
(Deprecated) Called every time when an Interactor begins hovering over this Interactable.
Declaration
public XRInteractableEvent onHoverEnter { get; }
Property Value
Type | Description |
---|---|
XRInteractableEvent |
onHoverEntered
(Deprecated) Gets or sets the event that is called when an Interactor begins hovering over this Interactable.
Declaration
public XRInteractableEvent onHoverEntered { get; set; }
Property Value
Type | Description |
---|---|
XRInteractableEvent |
onHoverExit
(Deprecated) Called every time when an Interactor ends hovering over this Interactable.
Declaration
public XRInteractableEvent onHoverExit { get; }
Property Value
Type | Description |
---|---|
XRInteractableEvent |
onHoverExited
(Deprecated) Gets or sets the event that is called when an Interactor ends hovering over this Interactable.
Declaration
public XRInteractableEvent onHoverExited { get; set; }
Property Value
Type | Description |
---|---|
XRInteractableEvent |
onLastHoverExit
(Deprecated) Called only when the last Interactor ends hovering over this Interactable.
Declaration
public XRInteractableEvent onLastHoverExit { get; }
Property Value
Type | Description |
---|---|
XRInteractableEvent |
onLastHoverExited
(Deprecated) Gets or sets the event that is called only when the last remaining hovering Interactor ends hovering over this Interactable.
Declaration
public XRInteractableEvent onLastHoverExited { get; set; }
Property Value
Type | Description |
---|---|
XRInteractableEvent |
onSelectCancel
(Deprecated) Called when the Interactor selecting this Interactable is disabled or destroyed.
Declaration
public XRInteractableEvent onSelectCancel { get; }
Property Value
Type | Description |
---|---|
XRInteractableEvent |
onSelectCanceled
(Deprecated) Gets or sets the event that is called when this Interactable is selected by an Interactor and either is unregistered (such as from being disabled or destroyed).
Declaration
public XRInteractableEvent onSelectCanceled { get; set; }
Property Value
Type | Description |
---|---|
XRInteractableEvent |
onSelectEnter
(Deprecated) Called when an Interactor begins selecting this Interactable.
Declaration
public XRInteractableEvent onSelectEnter { get; }
Property Value
Type | Description |
---|---|
XRInteractableEvent |
onSelectEntered
(Deprecated) Gets or sets the event that is called when an Interactor begins selecting this Interactable.
Declaration
public XRInteractableEvent onSelectEntered { get; set; }
Property Value
Type | Description |
---|---|
XRInteractableEvent |
onSelectExit
(Deprecated) Called when an Interactor ends selecting this Interactable.
Declaration
public XRInteractableEvent onSelectExit { get; }
Property Value
Type | Description |
---|---|
XRInteractableEvent |
onSelectExited
(Deprecated) Gets or sets the event that is called when an Interactor ends selecting this Interactable.
Declaration
public XRInteractableEvent onSelectExited { get; set; }
Property Value
Type | Description |
---|---|
XRInteractableEvent |
selectEntered
Gets or sets the event that is called when an Interactor begins selecting this Interactable.
Declaration
public SelectEnterEvent selectEntered { get; set; }
Property Value
Type | Description |
---|---|
SelectEnterEvent |
Remarks
The SelectEnterEventArgs passed to each listener is only valid while the event is invoked, do not hold a reference to it.
See Also
selectExited
Gets or sets the event that is called when an Interactor ends selecting this Interactable.
Declaration
public SelectExitEvent selectExited { get; set; }
Property Value
Type | Description |
---|---|
SelectExitEvent |
Remarks
The SelectExitEventArgs passed to each listener is only valid while the event is invoked, do not hold a reference to it.
See Also
selectingInteractor
The interactor that is selecting this interactable (may be null).
Declaration
public XRBaseInteractor selectingInteractor { get; protected set; }
Property Value
Type | Description |
---|---|
XRBaseInteractor |
Remarks
Unity automatically sets this value during OnSelectEntering(SelectEnterEventArgs) and OnSelectExiting(SelectExitEventArgs) and should not typically need to be set by a user. The setter is langword_csharp_protected to allow for rare scenarios where a derived class needs to control this value. Changing this value does not invoke select events.
See Also
Methods
AttachCustomReticle(XRBaseInteractor)
Attaches a custom reticle to the Interactable associated with an Interactor.
Declaration
public virtual void AttachCustomReticle(XRBaseInteractor interactor)
Parameters
Type | Name | Description |
---|---|---|
XRBaseInteractor | interactor | Interactor that is interacting with the Interactable. |
Awake()
See
Declaration
protected virtual void Awake()
GetDistanceSqrToInteractor(XRBaseInteractor)
Calculates distance squared to interactor (based on colliders).
Declaration
public virtual float GetDistanceSqrToInteractor(XRBaseInteractor interactor)
Parameters
Type | Name | Description |
---|---|---|
XRBaseInteractor | interactor | Interactor to calculate distance against. |
Returns
Type | Description |
---|---|
Single | Returns the minimum distance between the interactor and this interactable's colliders. |
IsHoverableBy(XRBaseInteractor)
Determines if this interactable can be hovered by a given interactor.
Declaration
public virtual bool IsHoverableBy(XRBaseInteractor interactor)
Parameters
Type | Name | Description |
---|---|---|
XRBaseInteractor | interactor | Interactor to check for a valid hover state with. |
Returns
Type | Description |
---|---|
Boolean | Returns true if hovering is valid this frame. Returns false if not. |
See Also
IsSelectableBy(XRBaseInteractor)
Determines if this interactable can be selected by a given interactor.
Declaration
public virtual bool IsSelectableBy(XRBaseInteractor interactor)
Parameters
Type | Name | Description |
---|---|---|
XRBaseInteractor | interactor | Interactor to check for a valid selection with. |
Returns
Type | Description |
---|---|
Boolean | Returns true if selection is valid this frame. Returns false if not. |
See Also
OnActivate(XRBaseInteractor)
(Deprecated) This method is called by the XRBaseControllerInteractor when the Interactor begins an activation event on this selected Interactable.
Declaration
protected virtual void OnActivate(XRBaseInteractor interactor)
Parameters
Type | Name | Description |
---|---|---|
XRBaseInteractor | interactor | Interactor that is sending the activate event. |
See Also
OnActivated(ActivateEventArgs)
This method is called by the XRBaseControllerInteractor when the Interactor begins an activation event on this selected Interactable.
Declaration
protected virtual void OnActivated(ActivateEventArgs args)
Parameters
Type | Name | Description |
---|---|---|
ActivateEventArgs | args | Event data containing the Interactor that is sending the activate event. |
Remarks
args
is only valid during this method call, do not hold a reference to it.
See Also
OnDeactivate(XRBaseInteractor)
(Deprecated) This method is called by the XRBaseControllerInteractor when the Interactor ends an activation event on this selected Interactable.
Declaration
protected virtual void OnDeactivate(XRBaseInteractor interactor)
Parameters
Type | Name | Description |
---|---|---|
XRBaseInteractor | interactor | Interactor that is sending the deactivate event. |
See Also
OnDeactivated(DeactivateEventArgs)
This method is called by the XRBaseControllerInteractor when the Interactor ends an activation event on this selected Interactable.
Declaration
protected virtual void OnDeactivated(DeactivateEventArgs args)
Parameters
Type | Name | Description |
---|---|---|
DeactivateEventArgs | args | Event data containing the Interactor that is sending the deactivate event. |
Remarks
args
is only valid during this method call, do not hold a reference to it.
See Also
OnDestroy()
See
Declaration
protected virtual void OnDestroy()
OnDisable()
See
Declaration
protected virtual void OnDisable()
OnEnable()
See
Declaration
protected virtual void OnEnable()
OnHoverEntered(HoverEnterEventArgs)
This method is called by the Interaction Manager when the Interactor first initiates hovering over an Interactable in a second pass.
Declaration
protected virtual void OnHoverEntered(HoverEnterEventArgs args)
Parameters
Type | Name | Description |
---|---|---|
HoverEnterEventArgs | args | Event data containing the Interactor that is initiating the hover. |
Remarks
args
is only valid during this method call, do not hold a reference to it.
See Also
OnHoverEntered(XRBaseInteractor)
(Deprecated) This method is called by the Interaction Manager when the Interactor first initiates hovering over an Interactable in a second pass.
Declaration
protected virtual void OnHoverEntered(XRBaseInteractor interactor)
Parameters
Type | Name | Description |
---|---|---|
XRBaseInteractor | interactor | Interactor that is initiating the hover. |
See Also
OnHoverEntering(HoverEnterEventArgs)
This method is called by the Interaction Manager right before the Interactor first initiates hovering over an Interactable in a first pass.
Declaration
protected virtual void OnHoverEntering(HoverEnterEventArgs args)
Parameters
Type | Name | Description |
---|---|---|
HoverEnterEventArgs | args | Event data containing the Interactor that is initiating the hover. |
Remarks
args
is only valid during this method call, do not hold a reference to it.
See Also
OnHoverEntering(XRBaseInteractor)
(Deprecated) This method is called by the Interaction Manager right before the Interactor first initiates hovering over an Interactable in a first pass.
Declaration
protected virtual void OnHoverEntering(XRBaseInteractor interactor)
Parameters
Type | Name | Description |
---|---|---|
XRBaseInteractor | interactor | Interactor that is initiating the hover. |
See Also
OnHoverExited(HoverExitEventArgs)
This method is called by the Interaction Manager when the Interactor ends hovering over an Interactable in a second pass.
Declaration
protected virtual void OnHoverExited(HoverExitEventArgs args)
Parameters
Type | Name | Description |
---|---|---|
HoverExitEventArgs | args | Event data containing the Interactor that is ending the hover. |
Remarks
args
is only valid during this method call, do not hold a reference to it.
See Also
OnHoverExited(XRBaseInteractor)
(Deprecated) This method is called by the Interaction Manager when the Interactor ends hovering over an Interactable in a second pass.
Declaration
protected virtual void OnHoverExited(XRBaseInteractor interactor)
Parameters
Type | Name | Description |
---|---|---|
XRBaseInteractor | interactor | Interactor that is ending the hover. |
See Also
OnHoverExiting(HoverExitEventArgs)
This method is called by the Interaction Manager right before the Interactor ends hovering over an Interactable in a first pass.
Declaration
protected virtual void OnHoverExiting(HoverExitEventArgs args)
Parameters
Type | Name | Description |
---|---|---|
HoverExitEventArgs | args | Event data containing the Interactor that is ending the hover. |
Remarks
args
is only valid during this method call, do not hold a reference to it.
See Also
OnHoverExiting(XRBaseInteractor)
(Deprecated) This method is called by the Interaction Manager right before the Interactor ends hovering over an Interactable in a first pass.
Declaration
protected virtual void OnHoverExiting(XRBaseInteractor interactor)
Parameters
Type | Name | Description |
---|---|---|
XRBaseInteractor | interactor | Interactor that is ending the hover. |
See Also
OnRegistered(InteractableRegisteredEventArgs)
This method is called by the Interaction Manager when this Interactable is registered with it.
Declaration
protected virtual void OnRegistered(InteractableRegisteredEventArgs args)
Parameters
Type | Name | Description |
---|---|---|
InteractableRegisteredEventArgs | args | Event data containing the Interaction Manager that registered this Interactable. |
Remarks
args
is only valid during this method call, do not hold a reference to it.
See Also
OnSelectCanceled(XRBaseInteractor)
(Deprecated) This method is called by the Interaction Manager while this Interactable is selected by an Interactor when either is unregistered (such as from being disabled or destroyed) in a second pass.
Declaration
protected virtual void OnSelectCanceled(XRBaseInteractor interactor)
Parameters
Type | Name | Description |
---|---|---|
XRBaseInteractor | interactor | Interactor that is ending the selection. |
See Also
OnSelectCanceling(XRBaseInteractor)
(Deprecated) This method is called by the Interaction Manager while this Interactable is selected by an Interactor right before either is unregistered (such as from being disabled or destroyed) in a first pass.
Declaration
protected virtual void OnSelectCanceling(XRBaseInteractor interactor)
Parameters
Type | Name | Description |
---|---|---|
XRBaseInteractor | interactor | Interactor that is ending the selection. |
See Also
OnSelectEntered(SelectEnterEventArgs)
This method is called by the Interaction Manager when the Interactor first initiates selection of an Interactable in a second pass.
Declaration
protected virtual void OnSelectEntered(SelectEnterEventArgs args)
Parameters
Type | Name | Description |
---|---|---|
SelectEnterEventArgs | args | Event data containing the Interactor that is initiating the selection. |
Remarks
args
is only valid during this method call, do not hold a reference to it.
See Also
OnSelectEntered(XRBaseInteractor)
(Deprecated) This method is called by the Interaction Manager when the Interactor first initiates selection of an Interactable in a second pass.
Declaration
protected virtual void OnSelectEntered(XRBaseInteractor interactor)
Parameters
Type | Name | Description |
---|---|---|
XRBaseInteractor | interactor | Interactor that is initiating the selection. |
See Also
OnSelectEntering(SelectEnterEventArgs)
This method is called by the Interaction Manager right before the Interactor first initiates selection of an Interactable in a first pass.
Declaration
protected virtual void OnSelectEntering(SelectEnterEventArgs args)
Parameters
Type | Name | Description |
---|---|---|
SelectEnterEventArgs | args | Event data containing the Interactor that is initiating the selection. |
Remarks
args
is only valid during this method call, do not hold a reference to it.
See Also
OnSelectEntering(XRBaseInteractor)
(Deprecated) This method is called by the Interaction Manager right before the Interactor first initiates selection of an Interactable in a first pass.
Declaration
protected virtual void OnSelectEntering(XRBaseInteractor interactor)
Parameters
Type | Name | Description |
---|---|---|
XRBaseInteractor | interactor | Interactor that is initiating the selection. |
See Also
OnSelectExited(SelectExitEventArgs)
This method is called by the Interaction Manager when the Interactor ends selection of an Interactable in a second pass.
Declaration
protected virtual void OnSelectExited(SelectExitEventArgs args)
Parameters
Type | Name | Description |
---|---|---|
SelectExitEventArgs | args | Event data containing the Interactor that is ending the selection. |
Remarks
args
is only valid during this method call, do not hold a reference to it.
See Also
OnSelectExited(XRBaseInteractor)
(Deprecated) This method is called by the Interaction Manager when the Interactor ends selection of an Interactable in a second pass.
Declaration
protected virtual void OnSelectExited(XRBaseInteractor interactor)
Parameters
Type | Name | Description |
---|---|---|
XRBaseInteractor | interactor | Interactor that is ending the selection. |
See Also
OnSelectExiting(SelectExitEventArgs)
This method is called by the Interaction Manager right before the Interactor ends selection of an Interactable in a first pass.
Declaration
protected virtual void OnSelectExiting(SelectExitEventArgs args)
Parameters
Type | Name | Description |
---|---|---|
SelectExitEventArgs | args | Event data containing the Interactor that is ending the selection. |
Remarks
args
is only valid during this method call, do not hold a reference to it.
See Also
OnSelectExiting(XRBaseInteractor)
(Deprecated) This method is called by the Interaction Manager right before the Interactor ends selection of an Interactable in a first pass.
Declaration
protected virtual void OnSelectExiting(XRBaseInteractor interactor)
Parameters
Type | Name | Description |
---|---|---|
XRBaseInteractor | interactor | Interactor that is ending the selection. |
See Also
OnUnregistered(InteractableUnregisteredEventArgs)
This method is called by the Interaction Manager when this Interactable is unregistered from it.
Declaration
protected virtual void OnUnregistered(InteractableUnregisteredEventArgs args)
Parameters
Type | Name | Description |
---|---|---|
InteractableUnregisteredEventArgs | args | Event data containing the Interaction Manager that unregistered this Interactable. |
Remarks
args
is only valid during this method call, do not hold a reference to it.
See Also
ProcessInteractable(XRInteractionUpdateOrder.UpdatePhase)
This method is called by the Interaction Manager to update the Interactable. Please see the Interaction Manager documentation for more details on update order.
Declaration
public virtual void ProcessInteractable(XRInteractionUpdateOrder.UpdatePhase updatePhase)
Parameters
Type | Name | Description |
---|---|---|
XRInteractionUpdateOrder.UpdatePhase | updatePhase | The update phase this is called during. |
RemoveCustomReticle(XRBaseInteractor)
Removes a custom reticle so that it is no longer displayed on the Interactable.
Declaration
public virtual void RemoveCustomReticle(XRBaseInteractor interactor)
Parameters
Type | Name | Description |
---|---|---|
XRBaseInteractor | interactor | Interactor that is no longer interacting with the Interactable. |
Reset()
See
Declaration
protected virtual void Reset()
Events
registered
Calls the methods in its invocation list when this Interactable is registered with an Interaction Manager.
Declaration
public event Action<InteractableRegisteredEventArgs> registered
Event Type
Type | Description |
---|---|
Action<InteractableRegisteredEventArgs> |
Remarks
The InteractableRegisteredEventArgs passed to each listener is only valid while the event is invoked, do not hold a reference to it.
See Also
unregistered
Calls the methods in its invocation list when this Interactable is unregistered from an Interaction Manager.
Declaration
public event Action<InteractableUnregisteredEventArgs> unregistered
Event Type
Type | Description |
---|---|
Action<InteractableUnregisteredEventArgs> |
Remarks
The InteractableUnregisteredEventArgs passed to each listener is only valid while the event is invoked, do not hold a reference to it.