docs.unity3d.com
    Show / Hide Table of Contents

    Struct ARRaycastHit

    Represents the result of a raycast intersection with a trackable.

    Inherited Members
    ValueType.ToString()
    Object.Equals(Object, Object)
    Object.ReferenceEquals(Object, Object)
    Object.GetType()
    Namespace: UnityEngine.XR.ARFoundation
    Syntax
    public struct ARRaycastHit : IEquatable<ARRaycastHit>, IComparable<ARRaycastHit>

    Constructors

    ARRaycastHit(XRRaycastHit, Single, Transform)

    Constructor invoked by Raycast(Vector2, List<ARRaycastHit>, TrackableType) and Raycast(Ray, List<ARRaycastHit>, TrackableType).

    Declaration
    [Obsolete("Use ARRaycastHit(XRRaycastHit, float, Transform, ARTrackable) instead. (2020-10-09)")]
    public ARRaycastHit(XRRaycastHit hit, float distance, Transform transform)
    Parameters
    Type Name Description
    XRRaycastHit hit

    Session-relative raycast hit data.

    Single distance

    The distance, in Unity world space, of the hit.

    UnityEngine.Transform transform

    The Transform that transforms from session space to world space.

    Exceptions
    Type Condition
    ArgumentNullException

    Thrown if transform is null.

    ARRaycastHit(XRRaycastHit, Single, Transform, ARTrackable)

    Constructor invoked by Raycast(Vector2, List<ARRaycastHit>, TrackableType) and Raycast(Ray, List<ARRaycastHit>, TrackableType).

    Declaration
    public ARRaycastHit(XRRaycastHit hit, float distance, Transform transform, ARTrackable trackable)
    Parameters
    Type Name Description
    XRRaycastHit hit

    Session-relative raycast hit data.

    Single distance

    The distance, in Unity world space, of the hit.

    UnityEngine.Transform transform

    The Transform that transforms from session space to world space.

    ARTrackable trackable

    The trackable that was hit by this raycast, or null if no trackable was hit.

    Exceptions
    Type Condition
    ArgumentNullException

    Thrown if transform is null.

    Properties

    distance

    The distance, in Unity world space, from the ray origin to the intersection point.

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

    hitType

    The type of trackable hit by the raycast.

    Declaration
    public readonly TrackableType hitType { get; }
    Property Value
    Type Description
    TrackableType

    pose

    The Pose, in Unity world space, of the intersection point.

    Declaration
    public readonly Pose pose { get; }
    Property Value
    Type Description
    UnityEngine.Pose

    sessionRelativeDistance

    The distance, in local (session) space, from the ray origin to the intersection point.

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

    sessionRelativePose

    The Pose, in local (session) space, of the intersection point.

    Declaration
    public readonly Pose sessionRelativePose { get; }
    Property Value
    Type Description
    UnityEngine.Pose

    trackable

    The ARTrackable that this raycast hit, or null if no ARTrackable was hit. See hitType to determine what type of trackable, if any, was hit.

    Declaration
    public readonly ARTrackable trackable { get; }
    Property Value
    Type Description
    ARTrackable

    trackableId

    The session-unique identifier for the trackable that was hit.

    Declaration
    public readonly TrackableId trackableId { get; }
    Property Value
    Type Description
    TrackableId

    Methods

    CompareTo(ARRaycastHit)

    Used for sorting two raycast hits by distance. Uses CompareTo on the raycasts' distance properties.

    Declaration
    public int CompareTo(ARRaycastHit other)
    Parameters
    Type Name Description
    ARRaycastHit other

    The other ARRaycastHit to compare against.

    Returns
    Type Description
    Int32

    A value less than zero if this raycast hit is closer than other, zero if the distances are equal, and a positive value if other is closer.

    Implements
    IComparable<T>.CompareTo(T)

    Equals(Object)

    Tests for equality.

    Declaration
    public override bool Equals(object obj)
    Parameters
    Type Name Description
    Object obj

    The object to compare against.

    Returns
    Type Description
    Boolean

    True if obj is of type ARRaycastHit and Equals(ARRaycastHit) also returns true; otherwise false.

    Overrides
    ValueType.Equals(Object)

    Equals(ARRaycastHit)

    Tests for equality.

    Declaration
    public bool Equals(ARRaycastHit other)
    Parameters
    Type Name Description
    ARRaycastHit other

    The other ARRaycastHit to compare against.

    Returns
    Type Description
    Boolean

    True if every field in other is equal to this ARRaycastHit, otherwise false.

    Implements
    IEquatable<T>.Equals(T)

    GetHashCode()

    Generates a hash suitable for use with containers like HashSet and Dictionary.

    Declaration
    public override int GetHashCode()
    Returns
    Type Description
    Int32

    A hash code generated from this object's fields.

    Overrides
    ValueType.GetHashCode()

    Operators

    Equality(ARRaycastHit, ARRaycastHit)

    Tests for equality. Same as Equals(ARRaycastHit).

    Declaration
    public static bool operator ==(ARRaycastHit lhs, ARRaycastHit rhs)
    Parameters
    Type Name Description
    ARRaycastHit lhs

    The left-hand side of the comparison.

    ARRaycastHit rhs

    The right-hand side of the comparison.

    Returns
    Type Description
    Boolean

    True if lhs is equal to rhs, otherwise false.

    Inequality(ARRaycastHit, ARRaycastHit)

    Tests for inequality. Same as !Equals(ARRaycastHit).

    Declaration
    public static bool operator !=(ARRaycastHit lhs, ARRaycastHit rhs)
    Parameters
    Type Name Description
    ARRaycastHit lhs

    The left-hand side of the comparison.

    ARRaycastHit rhs

    The right-hand side of the comparison.

    Returns
    Type Description
    Boolean

    True if lhs is not equal to rhs, otherwise false.

    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