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.

Where are the biggest perf hits for using mesh colliders vs convex/box?

Discussion in 'Physics for ECS' started by snacktime, Sep 12, 2020.

  1. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,351
    We have geometry building block soup that is comprised of planes, boxes, non box convex hulls, and mesh colliders. All thrown together in various configurations. Colliders can come and go at runtime. it would be a lot simpler to just use mesh colliders all around.

    Creation performance isn't an issue as we can partition that to something manageable. I'm unsure about queries though and also memory usage. No dynamic bodies that would be interacting. Collider/ray casting against these would be fairly low.
     
  2. petarmHavok

    petarmHavok

    Joined:
    Nov 20, 2018
    Posts:
    461
    Memory usage is the main thing in your case, as query performance would probably be ok (although still slower).

    Even for simple thing like comparison of box vs. mesh representing a box, you need a lot more memory for the mesh case. Not to mention more complicated meshes. You can use the MemorySize field on every composite collider (and mesh is composite) to check the exact memory usage.

    May I ask, what is the use case for this? If you are not simulating dynamic bodies and are doing queries rarely, what is the scenario behind this world of many static bodies? Of course, if you can share that information.
     
  3. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,351
    It's for player created underground areas in a 3rd person game. Voxel like with surfaces constructed from a set of meshes that are mostly 2-4 triangles each.

    Currently I'm using a simple floor to nearest N to hash voxels to collider bounds and creating compounds of out of mostly box collider faces and some simple convex hulls. With the actual colliders prebuilt.
     
  4. Neto_Kokku

    Neto_Kokku

    Joined:
    Feb 15, 2018
    Posts:
    1,575
    You need to profile, but overall collisions and intersection testing with arbitrary meshes is more intensive than against parametric volumes (boxes, spheres, capsules, hulls, etc). For example, to calculate the ray intersection between a cube made of triangles you'd need 12 ray-triangle tests, when you could do it with a single ray-box test (which is also a simpler algorithm).
     
  5. Infinity8378

    Infinity8378

    Joined:
    Sep 27, 2015
    Posts:
    1
    ACTUALLY triangles are more effective nothing is truly 3D so it makes sense to do 2d collision you can use geometry collider algorithms and reduce or increase the triangle size or use them for 2d planar depth projection. this only takes O(n^2) memory read where a box takes O(n^3) . The depth in z can be mapped as an offset in y and x.
     
    Last edited: Sep 14, 2022