Legacy Documentation: Version 2017.1 (Go to current version)
LanguageEnglish
  • C#
  • JS

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

Physics.RaycastNonAlloc

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

public static function RaycastNonAlloc(ray: Ray, results: RaycastHit[], maxDistance: float = Mathf.Infinity, layerMask: int = DefaultRaycastLayers, queryTriggerInteraction: QueryTriggerInteraction = QueryTriggerInteraction.UseGlobal): int;
public static int RaycastNonAlloc(Ray ray, RaycastHit[] results, float maxDistance = Mathf.Infinity, int layerMask = DefaultRaycastLayers, QueryTriggerInteraction queryTriggerInteraction = QueryTriggerInteraction.UseGlobal);

Parameters

ray The starting point and direction of the ray.
results The buffer to store the hits into.
maxDistance The max distance the rayhit is allowed to be from the start of the ray.
layerMask A Layer mask that is used to selectively ignore colliders when casting a ray.
queryTriggerInteraction Specifies whether this query should hit Triggers.

Returns

int The amount of hits stored into the results buffer.

Description

Cast a ray through the scene and store the hits into the buffer.

Like Physics.RaycastAll, but generates no garbage.


public static function RaycastNonAlloc(origin: Vector3, direction: Vector3, results: RaycastHit[], maxDistance: float = Mathf.Infinity, layermask: int = DefaultRaycastLayers, queryTriggerInteraction: QueryTriggerInteraction = QueryTriggerInteraction.UseGlobal): int;
public static int RaycastNonAlloc(Vector3 origin, Vector3 direction, RaycastHit[] results, float maxDistance = Mathf.Infinity, int layermask = DefaultRaycastLayers, QueryTriggerInteraction queryTriggerInteraction = QueryTriggerInteraction.UseGlobal);

Parameters

origin The starting point and direction of the ray.
results The buffer to store the hits into.
direction The direction of the ray.
maxDistance The max distance the rayhit is allowed to be from the start of the ray.
layermask A Layer mask that is used to selectively ignore colliders when casting a ray.
queryTriggerInteraction Specifies whether this query should hit Triggers.

Returns

int The amount of hits stored into the results buffer.

Description

Cast a ray through the scene and store the hits into the buffer.

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