Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Why concave colliders aren't allowed anymore?

Discussion in 'Editor & General Support' started by darkhog, Jun 23, 2015.

  1. darkhog

    darkhog

    Joined:
    Dec 4, 2012
    Posts:
    2,218
    I'm genuinely curious why this was disabled for rigidbodies, since it worked fine and is basically necessary for levels build as a single mesh, etc.
     
    Last edited: Jun 23, 2015
    hellobody and juan-jo like this.
  2. PROTOFACTOR_Inc

    PROTOFACTOR_Inc

    Joined:
    Nov 15, 2009
    Posts:
    4,052
    Wait, what? You can't add mesh collider to a,3D object? Since when? V5.1?
     
  3. darkhog

    darkhog

    Joined:
    Dec 4, 2012
    Posts:
    2,218
    No, you can. You just need to mark it as "convex". Which works for things like barrels, but not when you have statue that has some holes in it that you can shoot through AND is affected by physics (rigidbody), well, good luck.
     
  4. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    20,952
  5. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,614
    You can always make a compound collider. Break the mesh up into pieces which are each convex, or use a number of primitive shapes. You can do the same thing, you just do it a different way that (ideally) ends up being more efficient.
     
  6. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,614
    If your level is built as a single mesh why does it need a Rigidbody?
     
  7. Kondor0

    Kondor0

    Joined:
    Feb 20, 2010
    Posts:
    601
    ChrisSch and NomadKing like this.
  8. PROTOFACTOR_Inc

    PROTOFACTOR_Inc

    Joined:
    Nov 15, 2009
    Posts:
    4,052
    Never had that problem... I just add a mesh collider and boom, et Voilà. It's just eating more ressources. Or maybe I'm missing something. Mesh collider is concave by default. Clicking convex will just optimize the collider by creating a rough bouding box
     
    hernanbrega likes this.
  9. Alex-Lian

    Alex-Lian

    Guest

    Not specifically a physics specialist, but IIRC, most algorithms for physics are much faster if only dealing with convex shapes. So, it is often still cheaper to subdivide a concave mesh into multiple convex meshes. Basically, it's the trade for convenience vs. performance.
     
    Deon-Cadme, Aurore and angrypenguin like this.
  10. darkhog

    darkhog

    Joined:
    Dec 4, 2012
    Posts:
    2,218
    Yes, but why force it? IMO it should be that way:

    - Convex in collider is selected - use faster algorithm
    - Convex isn't selected - use slower.

    And if someone would have issues regarding physics performance, stock answer should be "please limit amount of concave rigidbodies".
     
    AbleArcher likes this.
  11. Alex-Lian

    Alex-Lian

    Guest

    Again, not the physics expert, but my suspicion is that there is no "slower" algorithm offered. It probably did some sort of auto-subdivision in the background which is better left to the user to do is my guess. Though, I'm probably not the best to explain this...
     
    angrypenguin likes this.
  12. Tomnnn

    Tomnnn

    Joined:
    May 23, 2013
    Posts:
    4,148
    This is why I sometimes look down on the use of 3rd party libraries and technologies. I asked a potential interview some questions about how their stuff works and their best answer was a flow of interactions of 3rd party technologies doing behind the scenes woo woo and they have no idea what's going on.

    I understand that you shouldn't reinvent the wheel nor should you need to understand it 100% to make use of it... but come on ._. A feature people were making use of suddenly vanished and the best answer offered here (by @Ryiah) is PhysX updated aaaaand it's gone. The way it works now is better in every way... except for where concave colliders were needed. I don't personally use them or have any idea what's happening in this thread, but I'm drawn in by the inconvenience to other community members :p

    The only good to come of this is that it inspires people to make work arounds and actually code things. The nice thing about reinventing the wheel is that your car doesn't break when the 3rd party distributer releases wheel 2.0.
     
    juan-jo likes this.
  13. LaneFox

    LaneFox

    Joined:
    Jun 29, 2011
    Posts:
    7,462
    Considering the level of expertise of the average person using these systems the general response would be "physics is slow" and "why are my mobile builds bigger" because they have no clue that what they're doing is causing a problem.

    It's simple enough to just make a compound collider. It'll be okay.
     
    LMan and Ryiah like this.
  14. Jonny-Roy

    Jonny-Roy

    Joined:
    May 29, 2013
    Posts:
    666
    It is a PhysX 3 limitation, there may be more info on NVidia's forums, but ultimately Convex = Slow, if it's static, they can pre-optimize, but for moving ones its far more complex, simple answer, break it down to sub meshes, it's easy and will give far better performance than a single Convex mesh.
     
  15. Alex-Lian

    Alex-Lian

    Guest

    This goes off-topic slightly, but I figured I would still respond to this comment. This is something we struggle with regularly. We can hide the magic behind the curtain, but then there are places where the best person to make the decision as what to do is not us, but the game developer. So, we need to balance where pulling back the curtain is the appropriate approach. A lot of engineering is about trade-offs, and letting Unity make all the calls is not necessarily the best approach, even at the cost of inconvenience (sometimes).

    and...to try and set things straight I've tapped on a physics dev to try and respond.
     
    dadude123, angrypenguin and Tomnnn like this.
  16. MortenSkaaning

    MortenSkaaning

    Joined:
    Jan 16, 2015
    Posts:
    120
  17. ShilohGames

    ShilohGames

    Joined:
    Mar 24, 2014
    Posts:
    3,015
    In my opinion, where Unity needs to address this is on the tools side. There should be a tool built into Unity for generating various types of optimized colliders. I agree with the idea behind forcing game developers to use optimized colliders, but Unity should have included the tools in Unity 5.0 to do that.

    As it is right now, I have to use 3rd party tools to make optimized collision meshes. In my case, I use MeshLab and Blender to create the optimized collision meshes. It is not the end of the world, but the workflow would have been smoother if Unity 5 included a tool for generating various optimized meshes. For example, UnrealEngine includes a built in tool that makes it easy to generate collision meshes without 3rd party tools. It would be easy for Unity to include a similar feature.

    This is not an issue about engineering trade-offs. The issue is simply a lack of built in tools for generating the optimized colliders. If Unity included such a tool, nobody would be complaining about restrictions on concave mesh colliders in Unity 5. If the tool was built in, then everybody would be happily generating optimized convex mesh colliders using the tool.
     
    juan-jo and darkhog like this.
  18. 00christian00

    00christian00

    Joined:
    Jul 22, 2012
    Posts:
    1,035
    Just curious, how would you handle a situation where you are inside a pipe/tube shape? It would take a ton of colliders to recreate the shape in a convex shape.
    Something like a Fzero tunnel.
     
  19. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    20,952
    My approach would be to create a spline that follows the path of the tube and is centered within it. From there you would have two basic ways to check if the player is colliding.

    One is to simply check the distance of the player from the spline. Alternatively you could have a few colliders, in the shape of a tube, following the spline at all times and adjusting their positioning to match it.
     
    Last edited: Jun 23, 2015
    00christian00 likes this.
  20. Tomnnn

    Tomnnn

    Joined:
    May 23, 2013
    Posts:
    4,148
    Thank you for saying that :D

    And especially that :3

    It'd be interesting to use a procedural generation sort of technique to build the colliders near the edges of the vehicle as it turned around walls. Great idea for infinite runners & racing games.
     
  21. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,614
    Even just allowing that option might make the whole system slower by nature. Instead of being able to assume that all mesh rigids are convex it would have to be aware of and manage the difference in potentially all interactions, even when they're not in use.

    It sounds to me like the real issue is that people want the workflow to support concave meshes. For the most part, we really shouldn't care how it does things internally (and I, for one, choose to accept that the people at Unity and PhysX who've spent far more time on this than I probably know a little better than I do, anyway).

    So maybe if Unity exposed an auto-split function which creates and handles a set of convex colliders for us? Even that wouldn't be trivial, though, which is probably why they didn't just do it for us in the first place.
     
    Last edited: Jun 24, 2015
  22. Zeblote

    Zeblote

    Joined:
    Feb 8, 2013
    Posts:
    1,102
    Spawning a load of box colliders is probably still more efficient than a single concave collider. Also, can't static colliders still be concave without problems?
     
    angrypenguin likes this.
  23. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Yes they can.

    Use a concave mesh collider. There's no reason to put a rigidbody on it.

    --Eric
     
    angrypenguin likes this.
  24. 00christian00

    00christian00

    Joined:
    Jul 22, 2012
    Posts:
    1,035
    Oh, so the issue is just for rigidbody colliders? I don't understand all the fuss then.
     
    GibTreaty and Jonny-Roy like this.
  25. Jonny-Roy

    Jonny-Roy

    Joined:
    May 29, 2013
    Posts:
    666
    Me either, for the really small percentage of people this affects, just create them in the same system you are creating your meshes...

    I mean built in to Unity would be a niceness, but would I want to delay everything else UNET, GI, etc by months just for that....I don't think so.
     
  26. Tomnnn

    Tomnnn

    Joined:
    May 23, 2013
    Posts:
    4,148
    Anyone know if this would be solved if you modeled a tube shape in another program and used it for a mesh collider? I've done that to get an inverted circle for some awesome particle effects.
     
  27. LaneFox

    LaneFox

    Joined:
    Jun 29, 2011
    Posts:
    7,462
    You can still make concave colliders, just not on Rigidbodies.

    Docs
    http://docs.unity3d.com/Manual/class-MeshCollider.html
     
  28. Tomnnn

    Tomnnn

    Joined:
    May 23, 2013
    Posts:
    4,148
    What does that do if you model a torus? Would it block the hole in the center? Strange I've never tried that before, so I'm guessing the answer is yes. So "rigid torus" isn't possible in unity without a lot of small colliders?
     
  29. LaneFox

    LaneFox

    Joined:
    Jun 29, 2011
    Posts:
    7,462
    Static colliders dont need rigidbodies.
     
  30. Zeblote

    Zeblote

    Joined:
    Feb 8, 2013
    Posts:
    1,102
    If you want the torus to move, you'll need to split it up in a few convex colliders. If it's supposed to be static, it works with just the concave mesh collider.
     
  31. ShilohGames

    ShilohGames

    Joined:
    Mar 24, 2014
    Posts:
    3,015
    The issue only applies to rigidbodies where IsKinematic is false. If you set IsKinematic to true, you can still use concave mesh colliders with a rigidbody. But obviously this restricts how you can use rigidbodies with concave mesh colliders.

    The real issue is the lack of a built in tool for creating optimized collision meshes. It was always a bad idea (performance wise) to use concave mesh colliders with non-kinematic rigidbodies, but people got into the bad habit of doing that because it was easy. Unity should definitely add a built in tool for generating optimized colliders. It would be a nice time saver, and it would encourage best practices for new users. If they don't, I suspect they will have to answer this same question over and over forever.
     
    asdzxcv777 likes this.
  32. Tomnnn

    Tomnnn

    Joined:
    May 23, 2013
    Posts:
    4,148
    I guess that works. What is the use case for a 'rigid torus' anyway? Basketball hoop physics?
     
  33. Jonny-Roy

    Jonny-Roy

    Joined:
    May 29, 2013
    Posts:
    666
    Wouldn't that be static?
     
  34. Tomnnn

    Tomnnn

    Joined:
    May 23, 2013
    Posts:
    4,148
    Not if it wobbles and reacts with physics when the ball / player hits it :D Super unnecessary I know, but come on, people are trying to make HAIR PHYSICS work... physics based basketball hoops are coming.
     
  35. ShilohGames

    ShilohGames

    Joined:
    Mar 24, 2014
    Posts:
    3,015
    Maybe you could set up several pre-defined ball hoop animations and then play the ball hoop animation that makes the most sense relative to where the ball hit the hoop. It would give the illusion of being purely physics based without the overhead of being physics based.
     
  36. greggtwep16

    greggtwep16

    Joined:
    Aug 17, 2012
    Posts:
    1,546
    Even splitting the basketball rim into a compound collider is not a good idea (unless someone can point out something I'm missing). I've made two physics based games (one basketball) and a compound collider's seams always seems to be a problem. I've tried the seams overlapping or being exactly lined up and it always creates weird bounces on that invisible seam (I assume under the cover Unity iterates on the collider array and doesn't treat the seam as a joined solid piece). The game below in my signature the paddles aren't concave but I would have liked the performance boost of not using a mesh collider. On the basketball game I don't currently need wobble of the rim but again it would have been nice to be able to make a compound collider instead of a static mesh collider.

    I've tried so many combinations until I'm blue in the face, while I can see compound colliders being useful for a FPS where your doing raycasts or other types of games, I can't see it as useful for any game where the physics would be scrutinized. Hopefully, I'm just doing something wrong.
     
    Last edited: Jun 25, 2015
  37. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,614
    If it could treat seams as a solid piece then it'd essentially be treating the set of colliders as one concave hull, which is what's being avoided in the first place.

    You're right, seams are a pain. In my experience (which is limited in this kind of use case) you just need to design to minimize seams and tune the settings as best you can from there.

    For a basketball hoop in particular I'd probably look at a ring of capsule colliders, which I would expect to model the shape better than meshes (as it's round rather than faceted), minimise seams (as the ends are rounded) and be cheaper (primitive shape rather than a mesh). I haven't tested that in practice, though, and there are certainly use cases where finding a good solution with a real-time physics engine is more challenging.
     
  38. greggtwep16

    greggtwep16

    Joined:
    Aug 17, 2012
    Posts:
    1,546
    This was the conclusion I came to awhile back and its understandable. Technically, it wouldn't have to be treated as one concave hull as only the neighbors on the seams would have to be considered not the entire hull. In the basketball rim example lets say you have 20 capsule colliders forming the ring. Each seam would be a convergence of only two pieces of the 20 piece compound collider. In addition each seam if you treated the two neighbors as a solid piece would still be convex even though the object as a whole is a concave hull. I realize this is a huge amount of work though and I understand why Unity doesn't do it, just pointing out that it is possible for UT to deal with the seams if they wanted to (I wouldn't feel the special case is worth their effort though).

    When I was originally having this problem I tried this but the rounded ends actually make the problem worse in this particular case. I had written an editor script to auto generate the compound colliders for me with n number of segments in a ring fashion around a center point at radius x and actually the higher the number of segments used the worse the behavior of the ball bouncing off the rim got. All the tiny nubs sticking a little bit outside the end made for some weird bounces. In the end a simplified low vertex count invisible rim (the real higher vertex rim was for the visuals) worked the best with a static mesh collider. I didn't need rim movement or wobbling but if I did I would have probably animated it as I don't think there would be anyway to keep the realistic bouncing and have it move.

    The 3D pong game I made is where I really wanted the compound collider to work with seams. It was my first game and to distinguish it I made the arena and the paddles octagon shaped. The shape is convex but I would think 9 box colliders would have been more performant than the mesh collider and seemed to be when I profiled it but the seams made the bouncing bad so I had to stick with the mesh collider.

    I understand these cases are somewhat rare and I understand why UT doesn't support it just wanted to point out that these cases do exist.
     
  39. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,614
    Based on what you've said about the basketball ring I'd probably write custom physics handling for it, then. Use a box collider as a trigger to enable/disable a special behaviour, and when in that trigger have a custom sphere vs. ring routine. Sphere vs. ring should be relatively straightforward: use the angle to determine one point on the ring to check against, then examine the vector between that position and the ball's center - unless I'm missing something that should give you everything you need to detect collision, penetration distance and bounce direction.

    Still...
    ... yes, these cases definitely do exist, and some of them are probably far harder to solve than the above.
     
    greggtwep16 likes this.
  40. Tomnnn

    Tomnnn

    Joined:
    May 23, 2013
    Posts:
    4,148
    Sure, you could do that... I'm sure in every case I would do that. I'd probably write my own physics before trying to use built in physics for something so simple. But I know a few people who would never do any of that, and do something crazy like putting rigidbodies on everything and hoping for the best.
     
  41. stanzy

    stanzy

    Joined:
    Dec 12, 2016
    Posts:
    17
    Last edited: Mar 15, 2017
  42. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    20,952
    Oh. Joy. Lesser GPL. If I recall @neginfinity's posts correctly there are problems with that license and Unity. At the very least if I'm not mistaken the code would need to be converted into a library first before we could actually use it otherwise all of our code would become LGPLed too.

    If you don't want to use an alternative license is there any chance you can just throw it up on a store somewhere?
     
    Last edited: Feb 20, 2017
  43. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,554
    Good job digging up an old thread.

    Yup. If it is LGPL it must be either converted into a DLL, or you'll have to expose your entire sourcecode to the public. It is not as evil as GPL, but will be very annoying in Unity, where plugins often provide full source code and then get compiled into final release.
     
  44. stanzy

    stanzy

    Joined:
    Dec 12, 2016
    Posts:
    17
    Ok guys @Ryiah @neginfinity, I changed the license to MIT, so everything should be fine. But dont sell it in the asset store ... ;)
     
    Ryiah likes this.
  45. ippdev

    ippdev

    Joined:
    Feb 7, 2010
    Posts:
    3,850
    They work properly if it is a circular, squared, polygoned profile or oval tube.
     
    00christian00 likes this.