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

"Unity No Longer Supports Non-Kinematic, Non-Convex colliders" Best workaround?

Discussion in 'Physics' started by jimthegiant, Mar 18, 2015.

Thread Status:
Not open for further replies.
  1. jimthegiant

    jimthegiant

    Joined:
    Mar 13, 2015
    Posts:
    9
    I'm pretty new to Unity so maybe I'm missing something but here's my dilemma.

    According to an error message error "Non-convex MeshColliders with non-kinematic Rigidbodies are no longer supported in Unity 5.0" but this is a necessity on one of my assets:

    push ramp.png

    The ramp needs pushing in to place by the players before they use it to access another area. For this to work the mesh collider needs to by the same as the visible mesh. If I click convex so it is pushable from the front clearly I can't also roll up it, if I use a wedge mesh I can't also push it.

    The only solution I've been able to make work is splitting the mesh in to left, middle and right sections then attaching each as a separate mesh collider.

    It's not a huge issue but it could be a lot harder with more complex shapes or if I need to add lots of different concave physically driven shapes to a scene in the future. Is there a better way?

    Could a script do the job of non kinematic physics calculation and be attached to every "kinematic" object where it's necessary?
     
  2. Nanako

    Nanako

    Joined:
    Sep 24, 2014
    Posts:
    1,047
    i'd probably make that with a wedge and two boxes.

    i wonder why this feature has been removed, though
     
  3. jimthegiant

    jimthegiant

    Joined:
    Mar 13, 2015
    Posts:
    9
    My guess would be performance but still would be nice to have the option and perhaps a warning.
    Maybe even having the option causes performance decrease but unity could have provided a script or a button to automatically split the mesh and add them as collider components to get around this.
     
  4. Roni92

    Roni92

    Joined:
    Nov 29, 2013
    Posts:
    225
    Its Physx 3.3 thing, not Unity's.
     
    briandcruz67 and jimthegiant like this.
  5. Brainswitch

    Brainswitch

    Joined:
    Apr 24, 2013
    Posts:
    270
    You can have an extra GameObject with no rigidbody and the meshcollider that synchronises it's position with the GameObject that has the rigidbody.
     
  6. Roni92

    Roni92

    Joined:
    Nov 29, 2013
    Posts:
    225
    that was my friggin' idea, ya should credit me xd
     
    Westland likes this.
  7. johnpine

    johnpine

    Joined:
    Sep 19, 2015
    Posts:
    26
    this is funny error because I get it for all these old Elite game spaceships. They are pretty much convex I think. ( except the missile )
    Unity version 5.1.3p3
     
    litebox likes this.
  8. ArmyOfCamels

    ArmyOfCamels

    Joined:
    Feb 2, 2015
    Posts:
    3
    You have to set the collider to convex in unity, it doesn't check if the shape is convex on it self
     
    Thomas-Mountainborn likes this.
  9. ArmyOfCamels

    ArmyOfCamels

    Joined:
    Feb 2, 2015
    Posts:
    3

    Got the same problenmm, convex is not really an option

    Update: I just made a convex collider and a rigidbody on an extra layer and am syncing the postion every frame. That one collides with everything the ship could run into, but not the player
     
    Last edited: Oct 10, 2015
  10. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    It'd be nice if like the sprite system, Unity was able to generate compound colliders, but I guess your 3d package will have a plugin for the purpose.
     
  11. juan-jo

    juan-jo

    Joined:
    May 15, 2010
    Posts:
    162
    If it's only a problem of Physx, why the rigidbody collisions are still working as before, with a non convex collider?
    I find the problem only with the OnMouse…() events.
     
  12. Quakeulf

    Quakeulf

    Joined:
    Mar 26, 2013
    Posts:
    40
    What I do is split the object into smaller parts then import them into the unities so that it can have the mesh colliders.

    However this adds to work hours, drawcalls and complexity.

    This feels like a step back.
     
    juan-jo likes this.
  13. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Because the non convex collider does not have a rigidbody itself, or you only think it is (the actual shape isn't what you expect).

    It's a problem with Physx 3.3 because it's an optimisation that makes physics far faster. You should look up compound collider in the Unity manual. This way, many convex shapes can describe any possible mesh shape. The limitation is then removed.

    Unity are in a future version, automating this process.
     
    juan-jo likes this.
  14. stanzy

    stanzy

    Joined:
    Dec 12, 2016
    Posts:
    17
    Deleted User and juan-jo like this.
  15. sgower

    sgower

    Joined:
    Mar 9, 2015
    Posts:
    316
    Nice work stanzy. An alternative is the "ConcaveCollider" Unity asset. It looks like you are creating a bunch of box colliders, but that asset creates a configurable number of meshcolliders. I'm curious about which has better performance. I guess I can test this. The thing about the ConcaveCollier asset is that if you want to save the colliders as a Prefab, you need to save the Mesh objects it generates...which is kind of a hassle.

    Stanzy, could you configure your script to generate more or fewer colliders depending upon how accurate you want it to be?

    It bugs me that Unity doesn't support this and requires a work-around, because you can do some cool things with concave, non-kinematic mesh colliders!

    Here's a question: When you have all these extra colliders in place, how does this effect performance when the object is set to Kinematic? Would it be best to disable all the generated colliders, and use a normal non-convex Mesh Collider when the object isn't moving?
     
  16. sgower

    sgower

    Joined:
    Mar 9, 2015
    Posts:
    316
    Stanzy, I tried your script. It looks like it's plenty useful (and you can't beat the price!) for many things, but isn't accurate enough for some applications. Example: The ultimate test of non-kinematic objects with non-convex colliders is creating a chain out of Torus (donut) objects. When I tried using your script for this, the rings flew apart and wouldn't stay linked as a chain. For this, the Concave Collider script works fine. I think for a complex object that is simultaneously curving in so many directions, that the BoxColliders can't accurately handle this. You need a bunch of Mesh colliders for this. Still though, it's a great script, and it's definitely appreciated whenever people contribute things like this and give them away.
     
  17. stanzy

    stanzy

    Joined:
    Dec 12, 2016
    Posts:
    17
    Hi Spanky11,

    thanks, I am glad you find it useful! :)

    Yes, I agree, in some edge cases this approximation might not be accurate enough. But in most everyday scenarios your needs should be covered with that script, I believe.
    Problems most likely arise when you create objects that are located very close to each other right from the start, like you did with the segments of a chain. The chain rings will fly apart because the NonConvexMeshCollider creates a compound collider that covers a bit more then only the shape of the ring. Thus the colliders of two rings are in a collision state right from the start, which lets the physics engine overreact.
    I consider adding an option to create colliders that only cover the inner space of a mesh, instead of the current behaviour, which creates colliders that may cover "a bit more". That would make the script capable of being used for a chain built of rings.
    By the way: if you create your rings with a little bit of distance next to another, the current script should also work.
    Probably I'll create an improved version of the component that solves such edge cases, and put it on the unity asset store for a cheap price at some point.

    And yes, you are right, that "Concave Collider" asset from the asset store is kind of similar, it was also my first try to get my problem solved. I was a bit shocked by the price, which was around 50$ I believe, but if it would have solved my troubles, I would have been happy with that.
    Anyhow, unfortunately it didn't solve my problems. For multiple reasons:
    It crashed/froze unity a number of times. And it took hours to calculate. I literally let my PC run a couple of days in a row to get all my object colliders calculated.
    And in the end, after having spent a couple of days on that topic I found out that some of the prefabs I created with ConcaveCollider were broken (didn't work when loaded at runtime).
    That was actually the reason why I then spent a couple of days implementing my own solution. :)

    To your questions:

    - Yes, there is an option to specify how accurate you want the generated compound colliders to be. You specify it in the form of "Boxes per Edge", where 10 means, that the bounding box of your mesh will be segmented in 10x10x10=10.000 Boxes which are then collision checked and the surviving ones are merged together. More accuracy means higher performance cost, of course. But you should get a pretty good approximation with "Boxes Per Edge" = 20 which IMHO shouldn't even be a problem for a low performance device (i.e. smartphone) to handle at runtime.

    - Yes, when you have a non-moving object and you have the rigidbody set to Kinematic=true, you might get an even better performance when you use the inbuilt mesh collider set to non-convex. I am not sure, you might have to measure.
    The unity documentation about colliders says: "... collider [...] need not be the exact same shape as the object’s mesh and in fact, a rough approximation is often more efficient and indistinguishable in gameplay. The simplest (and least processor-intensive) colliders are the so-called primitive collider types [...] Mesh Colliders [...] are much more processor-intensive than primitive types, however, so use them sparingly to maintain good performance"
    So if the NonConvexMeshCollider is fast enough you can also use it.
    But of course: The focus of the script is to delivering a solution for concave, physics controlled objects (Rigidbody=false), a thing that is currently not properly covered in unity.

    Best regards

    Florian
     
    Last edited: Mar 15, 2017
  18. sgower

    sgower

    Joined:
    Mar 9, 2015
    Posts:
    316
    Good stuff here. Regarding the Concave collider asset, yes it's pricey ($45 now). It may have improved since you tried it. To get prefabs to work, you need to drag the object to the scene, run the script there, and have the "Enable prefab usage" checkbox clicked. This will ask you to specify the save file location for the mesh that it generates. The script does basically work, but it can be slow, and a bit flaky.
     
  19. juan-jo

    juan-jo

    Joined:
    May 15, 2010
    Posts:
    162
    Also ProBuilder can help you to modeling simpler collision meshes rigth inside Unity editor.
     
  20. stanzy

    stanzy

    Joined:
    Dec 12, 2016
    Posts:
    17
    @Spanky11: Well that Concave Collider Asset still has these problems, but nevermind, I don't want to hate here, actually it is decent work what they have done there, it's just not stable for every mesh and the prefab stuff is a bit of a pain.
    I have improved the script in the meantime, can do things like chains now:

    Will upload it to asset store soon. :)
     
  21. sgower

    sgower

    Joined:
    Mar 9, 2015
    Posts:
    316
    Nice work. So are you still using BoxColliders? What did you change in order to make the linking rings work? Can I test the updated script?
     
  22. stanzy

    stanzy

    Joined:
    Dec 12, 2016
    Posts:
    17
    @Spanky11:

    Thank you!
    Yes, the script is still using BoxColliders, but I had to implement a proper SpacialBinaryTree and a collision detection algorithm (I used möller-trumbore ray-triangle intersection) to find out which boxes are completely inside of the mesh, in good performance.
    This solves the unwanted collisions, that made the rings explode in the older version. :)

    But regarding the chains: if your main concern is chains, I would probably recommend using joints instead of rings with colliders, for performance and stability reasons, IMHO.

    Well, anyhow, as there was a lot of additional work involved and the component is now a lot more powerfull, I decided to now offer the script in the asset store.

    If you are quick, you can grab one of the free license keys I offer for the introduction here:
    https://forum.unity3d.com/threads/n...first-to-receive-one-of-the-free-keys.464568/

    => The NonConvexMeshCollider can now be found here.
     
    Last edited: Apr 4, 2017
  23. sgower

    sgower

    Joined:
    Mar 9, 2015
    Posts:
    316
    Hi, very generous. I believe all the keys are used up :) I assume the way to redeem is by going to my Account page and using "Redeem Voucher"?

    I'm definitely interested, but already spent quite a lot on the other asset that is basically working.
    But if your actually works better for me, it would be well worth the money.
    Can I buy it, try it, and then return for a refund if I don't end up using it?

    I have a few needs for concave colliders In my game, and the linking rings is just one of them. My game is a builder game, and so the user can place rings in the scene, and (if they so choose), link them together to make a chain. In the event that they do this, I want them to behave as expected.
     
    Last edited: Apr 5, 2017
  24. stanzy

    stanzy

    Joined:
    Dec 12, 2016
    Posts:
    17
  25. cshelton73

    cshelton73

    Joined:
    Jul 14, 2015
    Posts:
    2
    Ouch, this script went from free to $35 in a hurry. I think I'll just break up my mesh manually and use multiple convex colliders. That's arguably the "proper" solution and I'm sure it's way more efficient than using hundreds of granular colliders to solve.

    I'm setting up bowling pins which would generate 1000's of colliders per lane. Nice script, might be good for prototyping mesh shapes before finaling.
     
  26. stanzy

    stanzy

    Joined:
    Dec 12, 2016
    Posts:
    17
    @cshelton73:
    reduced it to 10 €, I think that's a reasonable/fair price. Won't make me rich anyhow. ;) Think I'll leave it like this.
     
  27. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    If you have purchased anything from an asset author please use pm system or the author's own thread. This is not a product support thread. Don't post here for support, and don't ever post your card numbers.
     
Thread Status:
Not open for further replies.