Class XRRayInteractor | XR Interaction Toolkit | 0.10.0-preview.7
docs.unity3d.com
    Show / Hide Table of Contents

    Class XRRayInteractor

    Interactor used for interacting with interactables at a distance. This is handled via raycasts that update the current set of valid targets for this interactor.

    Inheritance
    Object
    Object
    Component
    Behaviour
    MonoBehaviour
    XRBaseInteractor
    XRBaseControllerInteractor
    XRRayInteractor
    Inherited Members
    XRBaseControllerInteractor.selectActionTrigger
    XRBaseControllerInteractor.hideControllerOnSelect
    XRBaseControllerInteractor.playAudioClipOnSelectEntered
    XRBaseControllerInteractor.playAudioClipOnSelectEnter
    XRBaseControllerInteractor.audioClipForOnSelectEntered
    XRBaseControllerInteractor.audioClipForOnSelectEnter
    XRBaseControllerInteractor.AudioClipForOnSelectEnter
    XRBaseControllerInteractor.playAudioClipOnSelectExited
    XRBaseControllerInteractor.playAudioClipOnSelectExit
    XRBaseControllerInteractor.audioClipForOnSelectExited
    XRBaseControllerInteractor.audioClipForOnSelectExit
    XRBaseControllerInteractor.AudioClipForOnSelectExit
    XRBaseControllerInteractor.playAudioClipOnHoverEntered
    XRBaseControllerInteractor.playAudioClipOnHoverEnter
    XRBaseControllerInteractor.audioClipForOnHoverEntered
    XRBaseControllerInteractor.audioClipForOnHoverEnter
    XRBaseControllerInteractor.AudioClipForOnHoverEnter
    XRBaseControllerInteractor.playAudioClipOnHoverExited
    XRBaseControllerInteractor.playAudioClipOnHoverExit
    XRBaseControllerInteractor.audioClipForOnHoverExited
    XRBaseControllerInteractor.audioClipForOnHoverExit
    XRBaseControllerInteractor.AudioClipForOnHoverExit
    XRBaseControllerInteractor.playHapticsOnSelectEntered
    XRBaseControllerInteractor.playHapticsOnSelectEnter
    XRBaseControllerInteractor.hapticSelectEnterIntensity
    XRBaseControllerInteractor.hapticSelectEnterDuration
    XRBaseControllerInteractor.playHapticsOnSelectExited
    XRBaseControllerInteractor.playHapticsOnSelectExit
    XRBaseControllerInteractor.hapticSelectExitIntensity
    XRBaseControllerInteractor.hapticSelectExitDuration
    XRBaseControllerInteractor.playHapticsOnHoverEntered
    XRBaseControllerInteractor.playHapticsOnHoverEnter
    XRBaseControllerInteractor.hapticHoverEnterIntensity
    XRBaseControllerInteractor.hapticHoverEnterDuration
    XRBaseControllerInteractor.playHapticsOnHoverExited
    XRBaseControllerInteractor.hapticHoverExitIntensity
    XRBaseControllerInteractor.hapticHoverExitDuration
    XRBaseControllerInteractor.xrController
    XRBaseControllerInteractor.isSelectActive
    XRBaseControllerInteractor.isUISelectActive
    XRBaseControllerInteractor.OnHoverEntering(XRBaseInteractable)
    XRBaseControllerInteractor.OnHoverExiting(XRBaseInteractable)
    XRBaseControllerInteractor.SendHapticImpulse(Single, Single)
    XRBaseInteractor.interactionManager
    XRBaseInteractor.interactionLayerMask
    XRBaseInteractor.attachTransform
    XRBaseInteractor.startingSelectedInteractable
    XRBaseInteractor.onHoverEntered
    XRBaseInteractor.onHoverEnter
    XRBaseInteractor.onHoverExited
    XRBaseInteractor.onHoverExit
    XRBaseInteractor.onSelectEntered
    XRBaseInteractor.onSelectEnter
    XRBaseInteractor.onSelectExited
    XRBaseInteractor.onSelectExit
    XRBaseInteractor.allowHover
    XRBaseInteractor.allowSelect
    XRBaseInteractor.enableInteractions
    XRBaseInteractor.isPerformingManualInteraction
    XRBaseInteractor.selectTarget
    XRBaseInteractor.hoverTargets
    XRBaseInteractor.Reset()
    XRBaseInteractor.Start()
    XRBaseInteractor.OnDestroy()
    XRBaseInteractor.GetHoverTargets(List<XRBaseInteractable>)
    XRBaseInteractor.isHoverActive
    XRBaseInteractor.requireSelectExclusive
    XRBaseInteractor.selectedInteractableMovementTypeOverride
    XRBaseInteractor.OnHoverEntered(XRBaseInteractable)
    XRBaseInteractor.OnHoverExited(XRBaseInteractable)
    XRBaseInteractor.OnSelectEntered(XRBaseInteractable)
    XRBaseInteractor.OnSelectExited(XRBaseInteractable)
    XRBaseInteractor.StartManualInteraction(XRBaseInteractable)
    XRBaseInteractor.EndManualInteraction()
    MonoBehaviour.IsInvoking()
    MonoBehaviour.CancelInvoke()
    MonoBehaviour.Invoke(String, Single)
    MonoBehaviour.InvokeRepeating(String, Single, Single)
    MonoBehaviour.CancelInvoke(String)
    MonoBehaviour.IsInvoking(String)
    MonoBehaviour.StartCoroutine(String)
    MonoBehaviour.StartCoroutine(String, Object)
    MonoBehaviour.StartCoroutine(IEnumerator)
    MonoBehaviour.StartCoroutine_Auto(IEnumerator)
    MonoBehaviour.StopCoroutine(IEnumerator)
    MonoBehaviour.StopCoroutine(Coroutine)
    MonoBehaviour.StopCoroutine(String)
    MonoBehaviour.StopAllCoroutines()
    MonoBehaviour.print(Object)
    MonoBehaviour.useGUILayout
    MonoBehaviour.runInEditMode
    Behaviour.enabled
    Behaviour.isActiveAndEnabled
    Component.GetComponent(Type)
    Component.GetComponent<T>()
    Component.TryGetComponent(Type, Component)
    Component.TryGetComponent<T>(T)
    Component.GetComponent(String)
    Component.GetComponentInChildren(Type, Boolean)
    Component.GetComponentInChildren(Type)
    Component.GetComponentInChildren<T>(Boolean)
    Component.GetComponentInChildren<T>()
    Component.GetComponentsInChildren(Type, Boolean)
    Component.GetComponentsInChildren(Type)
    Component.GetComponentsInChildren<T>(Boolean)
    Component.GetComponentsInChildren<T>(Boolean, List<T>)
    Component.GetComponentsInChildren<T>()
    Component.GetComponentsInChildren<T>(List<T>)
    Component.GetComponentInParent(Type)
    Component.GetComponentInParent<T>()
    Component.GetComponentsInParent(Type, Boolean)
    Component.GetComponentsInParent(Type)
    Component.GetComponentsInParent<T>(Boolean)
    Component.GetComponentsInParent<T>(Boolean, List<T>)
    Component.GetComponentsInParent<T>()
    Component.GetComponents(Type)
    Component.GetComponents(Type, List<Component>)
    Component.GetComponents<T>(List<T>)
    Component.GetComponents<T>()
    Component.CompareTag(String)
    Component.SendMessageUpwards(String, Object, SendMessageOptions)
    Component.SendMessageUpwards(String, Object)
    Component.SendMessageUpwards(String)
    Component.SendMessageUpwards(String, SendMessageOptions)
    Component.SendMessage(String, Object)
    Component.SendMessage(String)
    Component.SendMessage(String, Object, SendMessageOptions)
    Component.SendMessage(String, SendMessageOptions)
    Component.BroadcastMessage(String, Object, SendMessageOptions)
    Component.BroadcastMessage(String, Object)
    Component.BroadcastMessage(String)
    Component.BroadcastMessage(String, SendMessageOptions)
    Component.transform
    Component.gameObject
    Component.tag
    Component.rigidbody
    Component.rigidbody2D
    Component.camera
    Component.light
    Component.animation
    Component.constantForce
    Component.renderer
    Component.audio
    Component.networkView
    Component.collider
    Component.collider2D
    Component.hingeJoint
    Component.particleSystem
    Object.GetInstanceID()
    Object.GetHashCode()
    Object.Equals(Object)
    Object.Instantiate(Object, Vector3, Quaternion)
    Object.Instantiate(Object, Vector3, Quaternion, Transform)
    Object.Instantiate(Object)
    Object.Instantiate(Object, Transform)
    Object.Instantiate(Object, Transform, Boolean)
    Object.Instantiate<T>(T)
    Object.Instantiate<T>(T, Vector3, Quaternion)
    Object.Instantiate<T>(T, Vector3, Quaternion, Transform)
    Object.Instantiate<T>(T, Transform)
    Object.Instantiate<T>(T, Transform, Boolean)
    Object.Destroy(Object, Single)
    Object.Destroy(Object)
    Object.DestroyImmediate(Object, Boolean)
    Object.DestroyImmediate(Object)
    Object.FindObjectsOfType(Type)
    Object.DontDestroyOnLoad(Object)
    Object.DestroyObject(Object, Single)
    Object.DestroyObject(Object)
    Object.FindSceneObjectsOfType(Type)
    Object.FindObjectsOfTypeIncludingAssets(Type)
    Object.FindObjectsOfType<T>()
    Object.FindObjectOfType<T>()
    Object.FindObjectsOfTypeAll(Type)
    Object.FindObjectOfType(Type)
    Object.ToString()
    Object.name
    Object.hideFlags
    Namespace: UnityEngine.XR.Interaction.Toolkit
    Syntax
    [DisallowMultipleComponent]
    [AddComponentMenu("XR/XR Ray Interactor")]
    public class XRRayInteractor : XRBaseControllerInteractor, IUIInteractor, ILineRenderable

    Properties

    acceleration

    Gravity of the projectile in the reference frame.

    Declaration
    public float acceleration { get; set; }
    Property Value
    Type Description
    Single

    Acceleration

    Declaration
    [Obsolete("Acceleration has been deprecated. Use acceleration instead. (UnityUpgradable) -> acceleration")]
    public float Acceleration { get; set; }
    Property Value
    Type Description
    Single

    additionalFlightTime

    Additional flight time after the projectile lands at the same height of the start point in the tracking space. Increase this value will make the end point drop lower in height.

    Declaration
    public float additionalFlightTime { get; set; }
    Property Value
    Type Description
    Single

    AdditionalFlightTime

    Declaration
    [Obsolete("AdditionalFlightTime has been deprecated. Use additionalFlightTime instead. (UnityUpgradable) -> additionalFlightTime")]
    public float AdditionalFlightTime { get; set; }
    Property Value
    Type Description
    Single

    allowAnchorControl

    Allows the user to move the attach anchor point using the joystick.

    Declaration
    public bool allowAnchorControl { get; set; }
    Property Value
    Type Description
    Boolean
    See Also
    rotateSpeed
    translateSpeed

    angle

    Gets the signed angle between the controller's forward direction and the tracking space.

    Declaration
    public float angle { get; }
    Property Value
    Type Description
    Single

    Angle

    Declaration
    [Obsolete("Angle has been deprecated. Use angle instead. (UnityUpgradable) -> angle")]
    public float Angle { get; }
    Property Value
    Type Description
    Single

    controlPointDistance

    Increase this value will make the peak of the curve further from the start point.

    Declaration
    public float controlPointDistance { get; set; }
    Property Value
    Type Description
    Single

    controlPointHeight

    Increase this value will make the peak of the curve higher relative to the start point.

    Declaration
    public float controlPointHeight { get; set; }
    Property Value
    Type Description
    Single

    enableUIInteraction

    Gets or sets whether this interactor is able to affect UI.

    Declaration
    public bool enableUIInteraction { get; set; }
    Property Value
    Type Description
    Boolean

    endPointDistance

    Increase this value distance will make the end of curve further from the start point.

    Declaration
    public float endPointDistance { get; set; }
    Property Value
    Type Description
    Single

    endPointHeight

    Decrease this value will make the end of the curve drop lower relative to the start point.

    Declaration
    public float endPointHeight { get; set; }
    Property Value
    Type Description
    Single

    hitDetectionType

    Sets which type of hit detection to use for the raycast.

    Declaration
    public XRRayInteractor.HitDetectionType hitDetectionType { get; set; }
    Property Value
    Type Description
    XRRayInteractor.HitDetectionType

    hoverTimeToSelect

    Gets or sets the number of seconds for which this interactor must hover over an object to select it if Hover To Select is enabled.

    Declaration
    public float hoverTimeToSelect { get; set; }
    Property Value
    Type Description
    Single

    hoverToSelect

    Gets or sets whether this uses hovering for a time period to select the interactable being hovered.

    Declaration
    public bool hoverToSelect { get; set; }
    Property Value
    Type Description
    Boolean

    keepSelectedTargetValid

    Whether to keep selecting the target when not pointing to it after initially selecting it. It is recommended to set this value to true for grabbing objects, false for teleportation interactables.

    Declaration
    public bool keepSelectedTargetValid { get; set; }
    Property Value
    Type Description
    Boolean

    lineType

    Gets or sets the type of ray cast.

    Declaration
    public XRRayInteractor.LineType lineType { get; set; }
    Property Value
    Type Description
    XRRayInteractor.LineType

    maxRaycastDistance

    Gets or sets the max distance of ray cast. Increase this value will let you reach further.

    Declaration
    public float maxRaycastDistance { get; set; }
    Property Value
    Type Description
    Single

    originalAttachTransform

    The Transform that upon entering selection (when this interactor first initiates selection of an interactable), this interactor will copy the pose of the attach Transform values into.

    Declaration
    protected Transform originalAttachTransform { get; set; }
    Property Value
    Type Description
    Transform
    Remarks

    Automatically instantiated and set in Awake(). Setting this will not automatically destroy the previous object.

    See Also
    attachTransform

    raycastMask

    Gets or sets layer mask used for limiting raycast targets.

    Declaration
    public LayerMask raycastMask { get; set; }
    Property Value
    Type Description
    LayerMask

    raycastTriggerInteraction

    Gets or sets type of interaction with trigger volumes via raycast.

    Declaration
    public QueryTriggerInteraction raycastTriggerInteraction { get; set; }
    Property Value
    Type Description
    QueryTriggerInteraction

    referenceFrame

    Gets or sets the reference frame of the projectile. If not set it will try to find the rig object, and if that does not exist it will use its own Transform by default.

    Declaration
    public Transform referenceFrame { get; set; }
    Property Value
    Type Description
    Transform

    rotateSpeed

    Speed that the anchor is rotated.

    Declaration
    public float rotateSpeed { get; set; }
    Property Value
    Type Description
    Single
    See Also
    allowAnchorControl
    translateSpeed

    sampleFrequency

    Gets or sets the number of sample points of the curve, should be at least 3, the higher the better quality.

    Declaration
    public int sampleFrequency { get; set; }
    Property Value
    Type Description
    Int32

    sphereCastRadius

    Gets or sets radius used for sphere casting. Will use regular raycasting if set to 0 or less.

    Declaration
    public float sphereCastRadius { get; set; }
    Property Value
    Type Description
    Single

    translateSpeed

    Speed that the anchor is translated.

    Declaration
    public float translateSpeed { get; set; }
    Property Value
    Type Description
    Single
    See Also
    allowAnchorControl
    rotateSpeed

    useForceGrab

    Force grab moves the object to your hand rather than interacting with it at a distance.

    Declaration
    public bool useForceGrab { get; set; }
    Property Value
    Type Description
    Boolean

    validTargets

    List of interactables that this interactor could possibly interact with this frame. Populated during ProcessInteractor(XRInteractionUpdateOrder.UpdatePhase).

    Declaration
    protected override List<XRBaseInteractable> validTargets { get; }
    Property Value
    Type Description
    List<XRBaseInteractable>
    Overrides
    XRBaseControllerInteractor.validTargets

    velocity

    Initial velocity of the projectile. Increase this value will make the curve reach further.

    Declaration
    public float velocity { get; set; }
    Property Value
    Type Description
    Single

    Velocity

    Declaration
    [Obsolete("Velocity has been deprecated. Use velocity instead. (UnityUpgradable) -> velocity")]
    public float Velocity { get; set; }
    Property Value
    Type Description
    Single

    Methods

    Awake()

    Declaration
    protected override void Awake()
    Overrides
    XRBaseControllerInteractor.Awake()

    CanHover(XRBaseInteractable)

    Determines if the interactable is valid for hover this frame.

    Declaration
    public override bool CanHover(XRBaseInteractable interactable)
    Parameters
    Type Name Description
    XRBaseInteractable interactable

    Interactable to check.

    Returns
    Type Description
    Boolean

    Returns true if the interactable can be hovered over this frame.

    Overrides
    XRBaseInteractor.CanHover(XRBaseInteractable)

    CanSelect(XRBaseInteractable)

    Determines if the interactable is valid for selection this frame.

    Declaration
    public override bool CanSelect(XRBaseInteractable interactable)
    Parameters
    Type Name Description
    XRBaseInteractable interactable

    Interactable to check.

    Returns
    Type Description
    Boolean

    Returns true if the interactable can be selected this frame.

    Overrides
    XRBaseInteractor.CanSelect(XRBaseInteractable)

    GetCurrentRaycastHit(out RaycastHit)

    This function will return the first raycast result, if any raycast results are available.

    Declaration
    public bool GetCurrentRaycastHit(out RaycastHit raycastHit)
    Parameters
    Type Name Description
    RaycastHit raycastHit

    When this method returns, contains the raycast result if available; otherwise, the default value.

    Returns
    Type Description
    Boolean

    Returns true if the raycastHit parameter contains a valid raycast result. Returns false otherwise.

    GetLinePoints(ref Vector3[], out Int32)

    Performs the computation to convert the sample points from their local positions to world space and outputs an array of those points to form a line.

    Declaration
    public bool GetLinePoints(ref Vector3[] linePoints, out int numPoints)
    Parameters
    Type Name Description
    Vector3[] linePoints

    When this method returns, contains the sample points if successful.

    Int32 numPoints

    When this method returns, contains the number of sample points if successful.

    Returns
    Type Description
    Boolean

    Returns true if the sample points form a valid line, such as by having at least two points. Returns false otherwise.

    Implements
    ILineRenderable.GetLinePoints(ref Vector3[], out Int32)

    GetLinePoints(ref Vector3[], ref Int32, Int32)

    (Obsolete) Use GetLinePoints(ref Vector3[], out Int32) instead.

    Declaration
    [Obsolete("GetLinePoints with ref int parameter has been deprecated. Use signature with out int parameter instead.")]
    public bool GetLinePoints(ref Vector3[] linePoints, ref int numPoints, int _ = 0)
    Parameters
    Type Name Description
    Vector3[] linePoints

    Obsolete.

    Int32 numPoints

    Obsolete.

    Int32 _

    Dummy value to support old function signature.

    Returns
    Type Description
    Boolean

    Obsolete.

    GetValidTargets(List<XRBaseInteractable>)

    Retrieve the list of interactables that this interactor could possibly interact with this frame. This list is sorted by priority (in this case distance).

    Declaration
    public override void GetValidTargets(List<XRBaseInteractable> validTargets)
    Parameters
    Type Name Description
    List<XRBaseInteractable> validTargets

    Populated List of interactables that are valid for selection or hover.

    Overrides
    XRBaseInteractor.GetValidTargets(List<XRBaseInteractable>)

    OnDisable()

    Declaration
    protected override void OnDisable()
    Overrides
    XRBaseInteractor.OnDisable()

    OnEnable()

    Declaration
    protected override void OnEnable()
    Overrides
    XRBaseInteractor.OnEnable()

    OnSelectEntering(XRBaseInteractable)

    Declaration
    protected override void OnSelectEntering(XRBaseInteractable interactable)
    Parameters
    Type Name Description
    XRBaseInteractable interactable
    Overrides
    XRBaseControllerInteractor.OnSelectEntering(XRBaseInteractable)

    OnSelectExiting(XRBaseInteractable)

    This method is called by the interaction manager right before the interactor ends selection of an interactable.

    Declaration
    protected override void OnSelectExiting(XRBaseInteractable interactable)
    Parameters
    Type Name Description
    XRBaseInteractable interactable

    Interactable that is no longer selected.

    Overrides
    XRBaseControllerInteractor.OnSelectExiting(XRBaseInteractable)
    See Also
    OnSelectExited(XRBaseInteractable)

    OnValidate()

    Declaration
    protected void OnValidate()

    ProcessInteractor(XRInteractionUpdateOrder.UpdatePhase)

    This method is called by the interaction manager to update the interactor. Please see the interaction manager documentation for more details on update order.

    Declaration
    public override void ProcessInteractor(XRInteractionUpdateOrder.UpdatePhase updatePhase)
    Parameters
    Type Name Description
    XRInteractionUpdateOrder.UpdatePhase updatePhase
    Overrides
    XRBaseControllerInteractor.ProcessInteractor(XRInteractionUpdateOrder.UpdatePhase)

    RotateAnchor(Transform, Single)

    Declaration
    protected virtual void RotateAnchor(Transform anchor, float directionAmount)
    Parameters
    Type Name Description
    Transform anchor
    Single directionAmount

    TranslateAnchor(Transform, Transform, Single)

    Declaration
    protected virtual void TranslateAnchor(Transform originalAnchor, Transform anchor, float directionAmount)
    Parameters
    Type Name Description
    Transform originalAnchor
    Transform anchor
    Single directionAmount

    TryGetHitInfo(out Vector3, out Vector3, out Int32, out Boolean)

    Gets the current raycast hit information., it will return the world position and the normal vector of the hit point, and its position in linePoints.

    Declaration
    public bool TryGetHitInfo(out Vector3 position, out Vector3 normal, out int positionInLine, out bool isValidTarget)
    Parameters
    Type Name Description
    Vector3 position

    When this method returns, contains the world position of the ray impact point if the raycast result is valid.

    Vector3 normal

    When this method returns, contains the world normal of the surface the ray hit if the raycast result is valid.

    Int32 positionInLine

    When this method returns, contains the index within the list of raycast points returned by GetLinePoints(ref Vector3[], out Int32).

    Boolean isValidTarget

    When this method returns, contains whether both the raycast result is valid and a valid target for interaction.

    Returns
    Type Description
    Boolean

    Returns true if the raycast result is valid. Returns false otherwise.

    Implements
    ILineRenderable.TryGetHitInfo(out Vector3, out Vector3, out Int32, out Boolean)

    TryGetHitInfo(ref Vector3, ref Vector3, ref Int32, ref Boolean, Int32)

    (Obsolete) Use TryGetHitInfo(out Vector3, out Vector3, out Int32, out Boolean) instead.

    Declaration
    [Obsolete("TryGetHitInfo with ref parameters has been deprecated. Use signature with out parameters instead.")]
    public bool TryGetHitInfo(ref Vector3 position, ref Vector3 normal, ref int positionInLine, ref bool isValidTarget, int _ = 0)
    Parameters
    Type Name Description
    Vector3 position

    Obsolete.

    Vector3 normal

    Obsolete.

    Int32 positionInLine

    Obsolete.

    Boolean isValidTarget

    Obsolete.

    Int32 _

    Dummy value to support old function signature.

    Returns
    Type Description
    Boolean

    Obsolete.

    TryGetUIModel(out TrackedDeviceModel)

    Attempts to retrieve the current UI Model.

    Declaration
    public bool TryGetUIModel(out TrackedDeviceModel model)
    Parameters
    Type Name Description
    TrackedDeviceModel model

    The returned model that reflects the UI state of this Interactor.

    Returns
    Type Description
    Boolean

    Returns true if the model was able to retrieved. Returns false otherwise.

    Implements
    IUIInteractor.TryGetUIModel(out TrackedDeviceModel)

    UpdateUIModel(ref TrackedDeviceModel)

    Updates the current UI Model to match the state of the Interactor.

    Declaration
    public void UpdateUIModel(ref TrackedDeviceModel model)
    Parameters
    Type Name Description
    TrackedDeviceModel model

    The returned model that will match this Interactor.

    Implements
    IUIInteractor.UpdateUIModel(ref TrackedDeviceModel)
    Back to top
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023