docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class XRRaycastSubsystem

    Base class for a raycast subsystem.

    Inheritance
    object
    SubsystemWithProvider
    SubsystemWithProvider<XRRaycastSubsystem, XRRaycastSubsystemDescriptor, XRRaycastSubsystem.Provider>
    TrackingSubsystem<XRRaycast, XRRaycastSubsystem, XRRaycastSubsystemDescriptor, XRRaycastSubsystem.Provider>
    XRRaycastSubsystem
    Implements
    ISubsystem
    Inherited Members
    TrackingSubsystem<XRRaycast, XRRaycastSubsystem, XRRaycastSubsystemDescriptor, XRRaycastSubsystem.Provider>.GetChanges(Allocator)
    SubsystemWithProvider<XRRaycastSubsystem, XRRaycastSubsystemDescriptor, XRRaycastSubsystem.Provider>.OnCreate()
    SubsystemWithProvider<XRRaycastSubsystem, XRRaycastSubsystemDescriptor, XRRaycastSubsystem.Provider>.OnStart()
    SubsystemWithProvider<XRRaycastSubsystem, XRRaycastSubsystemDescriptor, XRRaycastSubsystem.Provider>.OnStop()
    SubsystemWithProvider<XRRaycastSubsystem, XRRaycastSubsystemDescriptor, XRRaycastSubsystem.Provider>.OnDestroy()
    SubsystemWithProvider<XRRaycastSubsystem, XRRaycastSubsystemDescriptor, XRRaycastSubsystem.Provider>.subsystemDescriptor
    SubsystemWithProvider<XRRaycastSubsystem, XRRaycastSubsystemDescriptor, XRRaycastSubsystem.Provider>.provider
    SubsystemWithProvider.Start()
    SubsystemWithProvider.OnStart()
    SubsystemWithProvider.Stop()
    SubsystemWithProvider.OnStop()
    SubsystemWithProvider.Destroy()
    SubsystemWithProvider.OnDestroy()
    SubsystemWithProvider.running
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: UnityEngine.XR.ARSubsystems
    Assembly: Unity.XR.ARSubsystems.dll
    Syntax
    public class XRRaycastSubsystem : TrackingSubsystem<XRRaycast, XRRaycastSubsystem, XRRaycastSubsystemDescriptor, XRRaycastSubsystem.Provider>, ISubsystem
    Remarks

    This abstract class should be implemented by an XR provider and instantiated using the SubsystemManager to enumerate the available XRRaycastSubsystemDescriptors.

    Constructors

    XRRaycastSubsystem()

    Constructor. Do not invoke directly; use the SubsystemManager to enumerate the available XRRaycastSubsystemDescriptors and call Create on the desired descriptor.

    Declaration
    public XRRaycastSubsystem()

    Methods

    GetChanges(Allocator)

    Get the changes to the tracked raycasts (arrays of added, updated and removed) since the last call to this method.

    Declaration
    public override TrackableChanges<XRRaycast> GetChanges(Allocator allocator)
    Parameters
    Type Name Description
    Allocator allocator

    An allocator to use for the returned container.

    Returns
    Type Description
    TrackableChanges<XRRaycast>

    The set of changes since the last call to this method. The caller owns the data and is responsible for calling Dispose() on it.

    Overrides
    TrackingSubsystem<XRRaycast, XRRaycastSubsystem, XRRaycastSubsystemDescriptor, XRRaycastSubsystem.Provider>.GetChanges(Allocator)

    Raycast(Ray, TrackableType, Allocator)

    Casts ray against trackables specified with trackableTypeMask.

    Declaration
    public NativeArray<XRRaycastHit> Raycast(Ray ray, TrackableType trackableTypeMask, Allocator allocator)
    Parameters
    Type Name Description
    Ray ray

    A ray in session space.

    TrackableType trackableTypeMask

    The types of trackables to test for ray intersections.

    Allocator allocator

    The Allocator used to allocate the returned NativeArray.

    Returns
    Type Description
    NativeArray<XRRaycastHit>

    A NativeArray of all the resulting ray intersections.

    Raycast(Vector2, TrackableType, Allocator)

    Casts a ray originating from screenPoint against trackables specified with trackableTypeMask.

    Declaration
    public NativeArray<XRRaycastHit> Raycast(Vector2 screenPoint, TrackableType trackableTypeMask, Allocator allocator)
    Parameters
    Type Name Description
    Vector2 screenPoint

    A point on the screen in normalized screen coordinates (0, 0) - (1, 1).

    TrackableType trackableTypeMask

    The types of trackables to test for ray intersections.

    Allocator allocator

    The Allocator used to allocate the returned NativeArray.

    Returns
    Type Description
    NativeArray<XRRaycastHit>

    A NativeArray of all the resulting ray intersections.

    RemoveRaycast(TrackableId)

    Removes an existing raycast by its TrackableId.

    Declaration
    public void RemoveRaycast(TrackableId trackableId)
    Parameters
    Type Name Description
    TrackableId trackableId

    The unique identifier for the raycast to remove.

    TryAddRaycast(Ray, float, out XRRaycast)

    Attempts to add a new persistent raycast. The raycast will be updated automatically until this subsystem is stopped or destroyed, or the the raycast is removed with RemoveRaycast(TrackableId).

    Declaration
    public bool TryAddRaycast(Ray ray, float estimatedDistance, out XRRaycast raycast)
    Parameters
    Type Name Description
    Ray ray

    A ray relative to the session origin defining the raycast.

    float estimatedDistance

    The estimated distance to the raycast target. For example, an average human height might be used to estimate the distance to the floor.

    XRRaycast raycast

    The newly added raycast. All spatial data is relative to the session origin.

    Returns
    Type Description
    bool

    True if the raycast was successfully added, or false otherwise.

    TryAddRaycast(Vector2, float, out XRRaycast)

    Attempts to add a new persistent raycast. The raycast will be updated automatically until this subsystem is stopped or destroyed, or the the raycast is removed with RemoveRaycast(TrackableId).

    Declaration
    public bool TryAddRaycast(Vector2 screenPoint, float estimatedDistance, out XRRaycast raycast)
    Parameters
    Type Name Description
    Vector2 screenPoint

    A point on the screen, in normalized screen coorindates (0, 0)..(1, 1).

    float estimatedDistance

    The estimated distance to the raycast target. For example, an average human height might be used to estimate the distance to the floor.

    XRRaycast raycast

    The newly added raycast. All spatial data is relative to the session origin.

    Returns
    Type Description
    bool

    True if the raycast was successfully added, or false otherwise.

    Implements

    ISubsystem

    Did you find this page useful? Please give it a rating:

    Thanks for rating this page!

    Report a problem on this page

    What kind of problem would you like to report?

    • This page needs code samples
    • Code samples do not work
    • Information is missing
    • Information is incorrect
    • Information is unclear or confusing
    • There is a spelling/grammar error on this page
    • Something else

    Thanks for letting us know! This page has been marked for review based on your feedback.

    If you have time, you can provide more information to help us fix the problem faster.

    Provide more information

    You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:

    You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:

    You've told us there is information missing from this page. Please tell us more about what's missing:

    You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:

    You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:

    You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:

    You've told us this page has a problem. Please tell us more about what's wrong:

    Thank you for helping to make the Unity documentation better!

    Your feedback has been submitted as a ticket for our documentation team to review.

    We are not able to reply to every ticket submitted.

    In This Article
    • Constructors
      • XRRaycastSubsystem()
    • Methods
      • GetChanges(Allocator)
      • Raycast(Ray, TrackableType, Allocator)
      • Raycast(Vector2, TrackableType, Allocator)
      • RemoveRaycast(TrackableId)
      • TryAddRaycast(Ray, float, out XRRaycast)
      • TryAddRaycast(Vector2, float, out XRRaycast)
    • Implements
    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)