docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class XRInteractableUtility

    Utility methods for Interactables.

    Inheritance
    object
    XRInteractableUtility
    Inherited Members
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: UnityEngine.XR.Interaction.Toolkit.Utilities
    Assembly: Unity.XR.Interaction.Toolkit.dll
    Syntax
    public static class XRInteractableUtility

    Methods

    TryGetClosestCollider(IXRInteractable, Vector3, out DistanceInfo)

    Calculates the closest Interactable's Collider to the given location (based on the Collider Transform position). The Collider volume and surface are not considered for calculation, use TryGetClosestPointOnCollider(IXRInteractable, Vector3, out DistanceInfo) in this case.

    Declaration
    public static bool TryGetClosestCollider(IXRInteractable interactable, Vector3 position, out DistanceInfo distanceInfo)
    Parameters
    Type Name Description
    IXRInteractable interactable

    Interactable to find the closest Collider position.

    Vector3 position

    Location in world space to calculate the closest Collider position.

    DistanceInfo distanceInfo

    If true is returned, distanceInfo will contain the closest Collider, its position (in world space) and its distance squared to the given location.

    Returns
    Type Description
    bool

    Returns true if the closest Collider can be computed, for this the interactable must have at least one active and enabled Collider. Otherwise, returns false.

    Remarks

    Only active and enabled non-trigger colliders are used in the calculation.

    See Also
    DistanceInfo
    TryGetClosestPointOnCollider(IXRInteractable, Vector3, out DistanceInfo)

    TryGetClosestPointOnCollider(IXRInteractable, Vector3, out DistanceInfo)

    Calculates the point on the Interactable's Colliders that is closest to the given location (based on the Collider volume and surface).

    Declaration
    public static bool TryGetClosestPointOnCollider(IXRInteractable interactable, Vector3 position, out DistanceInfo distanceInfo)
    Parameters
    Type Name Description
    IXRInteractable interactable

    Interactable to find the closest point.

    Vector3 position

    Location in world space to calculate the closest point.

    DistanceInfo distanceInfo

    If true is returned, distanceInfo will contain the point (in world space) on the Collider that is closest to the given location, its distance squared, and the Collider that contains the point. If the given location is in the Collider, the closest point will be inside. Otherwise, the closest point will be on the surface of the Collider.

    Returns
    Type Description
    bool

    Returns true if the closest point can be computed, for this the interactable must have at least one active and enabled Collider. Otherwise, returns false.

    Remarks

    Only active and enabled non-trigger colliders are used in the calculation. The colliders can only be a BoxCollider, SphereCollider, CapsuleCollider, or convex MeshCollider.

    See Also
    DistanceInfo
    TryGetClosestCollider(IXRInteractable, Vector3, out DistanceInfo)
    ClosestPoint(Vector3)
    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)