Skip to content

Latest commit

 

History

History
24 lines (17 loc) · 772 Bytes

UNT0028.md

File metadata and controls

24 lines (17 loc) · 772 Bytes

UNT0028 Use non-allocating physics APIs

Non-allocating versions of Physics query APIs have been introduced. You can replace RaycastAll calls with RaycastNonAlloc, SphereCastAll calls with SphereCastNonAlloc, and so on.

Examples of patterns that are flagged by this analyzer

using UnityEngine;

class Camera : MonoBehaviour
{
    void Update() {
        var result = Physics.RaycastAll(Vector3.zero, Vector3.zero);
        // ...
        result = Physics.RaycastAll(Vector3.zero, Vector3.zero);
    }
}

Solution

Instead of allocating a new array for each call, you can reuse a pre-allocated array to store the results. This will improve performance, especially for frequent calls.

No automatic code fix is available for this diagnostic.