Struct RaycastResult
A hit result from a BaseRaycaster.
Inherited Members
Namespace: UnityEngine.EventSystems
Assembly: UnityEngine.UI.dll
Syntax
public struct RaycastResult
  Fields
depth
Used by raycasters where elements may have the same unit distance, but have specific ordering.
Declaration
public int depth
  Field Value
| Type | Description | 
|---|---|
| int | 
displayIndex
The display index from which the raycast was generated.
Declaration
public int displayIndex
  Field Value
| Type | Description | 
|---|---|
| int | 
distance
Distance to the hit.
Declaration
public float distance
  Field Value
| Type | Description | 
|---|---|
| float | 
document
The UIToolkit Document that was intersected by this raycast, if any.
Declaration
public UIDocument document
  Field Value
| Type | Description | 
|---|---|
| UIDocument | 
Remarks
This is only useful in the context of EventSystem UI Toolkit interoperability.
element
The UIToolkit Visual Element that was intersected by this raycast, if any.
Declaration
public VisualElement element
  Field Value
| Type | Description | 
|---|---|
| VisualElement | 
Remarks
This is only useful in the context of EventSystem UI Toolkit interoperability.
index
Hit index
Declaration
public float index
  Field Value
| Type | Description | 
|---|---|
| float | 
module
BaseRaycaster that raised the hit.
Declaration
public BaseRaycaster module
  Field Value
| Type | Description | 
|---|---|
| BaseRaycaster | 
origin
The world position of the raycast ray origin.
Declaration
public Vector3 origin
  Field Value
| Type | Description | 
|---|---|
| Vector3 | 
screenPosition
The screen position from which the raycast was generated.
Declaration
public Vector2 screenPosition
  Field Value
| Type | Description | 
|---|---|
| Vector2 | 
sortingGroupID
The sorting group ID when the hit object is influenced by a SortingGroup.
Declaration
public int sortingGroupID
  Field Value
| Type | Description | 
|---|---|
| int | 
Remarks
For UI.Graphic elements will always be 0. For 3D objects this will always be 0. For 2D objects if a SortingOrder is influencing the same object as the hit collider then the renderers sortingGroupID will be used; otherwise SortingGroup.invalidSortingGroupID.
sortingGroupOrder
The sorting group order when the hit object is influenced by a SortingGroup.
Declaration
public int sortingGroupOrder
  Field Value
| Type | Description | 
|---|---|
| int | 
Remarks
For UI.Graphic elements this will always be 0. For 3D objects this will always be 0. For 2D objects if a SortingOrder is influencing the same object as the hit collider then the renderers sortingGroupOrder will be used.
sortingLayer
The SortingLayer of the hit object.
Declaration
public int sortingLayer
  Field Value
| Type | Description | 
|---|---|
| int | 
Remarks
For UI.Graphic elements this will be the values from that graphic's Canvas For 3D objects this will always be 0. For 2D objects if a 2D Renderer (Sprite, Tilemap, SpriteShape) is attached to the same object as the hit collider that sortingLayerID will be used.
sortingOrder
The SortingOrder for the hit object.
Declaration
public int sortingOrder
  Field Value
| Type | Description | 
|---|---|
| int | 
Remarks
For Graphic elements this will be the values from that graphics Canvas For 3D objects this will always be 0. For 2D objects if a 2D Renderer (Sprite, Tilemap, SpriteShape) is attached to the same object as the hit collider that sortingOrder will be used.
worldNormal
The normal at the hit location of the raycast.
Declaration
public Vector3 worldNormal
  Field Value
| Type | Description | 
|---|---|
| Vector3 | 
worldPosition
The world position of the where the raycast has hit.
Declaration
public Vector3 worldPosition
  Field Value
| Type | Description | 
|---|---|
| Vector3 | 
Properties
gameObject
The GameObject that was hit by the raycast.
Declaration
public GameObject gameObject { get; set; }
  Property Value
| Type | Description | 
|---|---|
| GameObject | 
isValid
Is there an associated module and a hit GameObject.
Declaration
public bool isValid { get; }
  Property Value
| Type | Description | 
|---|---|
| bool | 
Methods
Clear()
Reset the result.
Declaration
public void Clear()
  ToString()
Declaration
public override string ToString()
  Returns
| Type | Description | 
|---|---|
| string |