Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Moving Trigger vs. CheckSphere vs. Physics.OverlapSphereNonAlloc performance

Discussion in 'Physics' started by Johannski, Oct 12, 2017.

  1. Johannski

    Johannski

    Joined:
    Jan 25, 2014
    Posts:
    816
    I'm wondering if anybody did performance tests for checking simple sphere collisions. In my case I want to check if a sphere is overlapping another (concave) object. I had a moving trigger before, but read that those sometimes create performance issues. I'm wondering if Physics.CheckSphere ha better performance. And if Physics.OverlapSphereNonAlloc with a result array with just one entry has a similar performance.
     
  2. Rich_XR

    Rich_XR

    Joined:
    Jan 28, 2020
    Posts:
    9
    Did you ever get around to doing these checks at all?
     
  3. Johannski

    Johannski

    Joined:
    Jan 25, 2014
    Posts:
    816
    No, I think I went with CheckSphere, since I just needed to know if there is something on the layer I was checking for. I guess internally it is probably similar to OverlapSphere and just return true when the first element is found. So my guess would be, that OverlapSphereNonAlloc with an array of the size of one has pretty much the same performance.

    I think if you go with either one of the two, you should be quite safe performance wise, unless you call it every update on hundreds of objects (Then you should probably run some tests to see which method has the best performance).