Non-allocating versions of Physics query APIs have been introduced. You can replace RaycastAll
calls with RaycastNonAlloc
, SphereCastAll
calls with SphereCastNonAlloc
, and so on.
using UnityEngine;
class Camera : MonoBehaviour
{
void Update() {
var result = Physics.RaycastAll(Vector3.zero, Vector3.zero);
// ...
result = Physics.RaycastAll(Vector3.zero, Vector3.zero);
}
}
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.