Search Unity

Mesh Collider slowing down game

Discussion in 'Editor & General Support' started by xacto, Aug 13, 2005.

  1. xacto

    xacto

    Joined:
    Jul 20, 2005
    Posts:
    112
    I created a scene with a bunch of cups and as soon as I add a mesh collider to them, the game comes to a crawl. Is there any way to speed it up?
     
  2. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    Only static colliders (Colliders without rigid bodies) should have mesh colliders attached.
    If you want to create rigid bodies use primitive colliders.
     
  3. xacto

    xacto

    Joined:
    Jul 20, 2005
    Posts:
    112
    ok... I deleted all the rigid bodies from the cups and it looks like I have the same problem. :(
     
  4. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    Hmm.
    I can take a look at the performance problem if you submit a bug report on it.
    Don't forget to attach the project folder to it as well.
     
  5. xacto

    xacto

    Joined:
    Jul 20, 2005
    Posts:
    112
    Thanks for taking a look! :D
     
  6. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    The problem is that the sphere you shoot against the collide is too finely tesselated in relation to the size of the sphere.
    When the ball hits the cup, it will be in touch with thousands of triangles, this creates a lot of contacts, which slows the simulation down.

    There are two solutions:
    1) Use compound colliders, just create boxes and capsules in creative ways as children of your cup mesh. (Dont forget to remove the mesh collider on the cup)
    2) Create another version of the cup mesh with a lot fewer triangles. Limit it to 50 triangles, then assign the low poly mesh to the mesh collider by dragging the mesh onto the mesh property in the mesh collider inspector.
     
  7. xacto

    xacto

    Joined:
    Jul 20, 2005
    Posts:
    112
    THANK YOU! I will give them a try!! :D
     
  8. xacto

    xacto

    Joined:
    Jul 20, 2005
    Posts:
    112
    Hmm... ok I am trying solution 2. So... with this solution you are saying I can have a high triangle object rendered with a low triangle collider right?
    The file I sent you has two version of the cup. The original "CarniCup" is a high triangle, and the "smCup" object is the low triangle object (not 50 limit yet).

    There is a CarniCup on a table and when I drag the low triangle object onto the CarniCup's Mesh Collider, it just replaces the carniCup with the smCup. The game view shows the smCup. Is there a way to check to see the collider's mesh as well as the object's mesh?
     
  9. Richard_B

    Richard_B

    Joined:
    Jul 22, 2005
    Posts:
    436
    Xacto,
    You need to be in "Full" mode in the inspector to expose the Mesh Collider mesh - see below. Drag the low res mesh on to this one.

    Richard.
     

    Attached Files:

  10. xacto

    xacto

    Joined:
    Jul 20, 2005
    Posts:
    112
    Argh! ...your right, I had my inspector on simple. :D

    Thanks!
     
  11. klindeman

    klindeman

    Joined:
    Jun 13, 2005
    Posts:
    295
    That thing always gets me too...

    I am usually on expert just to make sure...
     
  12. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    Btw. expert mode is only useful for debugging scripts. It doesn't give you any extra editable properties.
     
  13. Jonathan Czeck

    Jonathan Czeck

    Joined:
    Mar 17, 2005
    Posts:
    1,713
    The only time I need to use Expert mode is when editing the texture size and depth of a render texture.

    -Jon
     
  14. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    True. Forgot about that.
     
  15. xacto

    xacto

    Joined:
    Jul 20, 2005
    Posts:
    112
    Is there a way to actually see the mesh in the mesh collider in unity? ( hi-rez mesh with a low rez collider)

    Everything was working perfectly, then all of a sudden my two meshes do not fit together anymore - its acting like a box collider now. I have a back up, so no big deal, but it would be nice to make sure they are matching up visually.
     
  16. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    Instead of adding the mesh collider to the high polymesh,
    add the low polymesh with a mesh renderer and everything as a child of the high polymesh.

    Then they both get renderered. Once your are happy with it, remove the mesh renderer from the low poly version.

    Btw. when i looked at your project, it contained skinned mesh filters for the cups. You might want to remove those again.
     
  17. xacto

    xacto

    Joined:
    Jul 20, 2005
    Posts:
    112
    [quote="Joachim Ante"add the low polymesh with a mesh renderer and everything as a child of the high polymesh. [/quote]

    Ah, great tip... that will work!!!

    And about the skinned mesh filter... I did not know I could delete that. What does that actually do anyway... could not find that in the manual.

    Thanks again for all the help!
     
  18. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    It is used when doing character animation. I guess when you imported the mesh it had some kind of character skin attached.
     
  19. xacto

    xacto

    Joined:
    Jul 20, 2005
    Posts:
    112
    I did as suggested and loaded my low polymesh as a child of the high polymesh and it told a lot about my problem. Again... great tip!

    Some how, my low mesh had a diferent rotation then my high mesh. I have been modeling in Modo, exporting it to Lightwave for saving it as a FBX file. (so things could get messed up -- ugh!)

    Now my question is... is there a way to rotate the low mesh to match my high mesh in unity (like transform), or will I have to adjust rotation in lightwave?
     
  20. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    Just rotate it. There is nothing special about colliders attached as children to other objects.
    You have set it up as a child of the real mesh right?
     
  21. Richard_B

    Richard_B

    Joined:
    Jul 22, 2005
    Posts:
    436
    Do both meshes have the same position and correct orientation in LightWave (before fbx exporting)? If so the low res mesh should be correct in Unity.

    If you just add the low res mesh to Unity scene is it rotated compred when it was in LightWave?

    Richard.
     
  22. xacto

    xacto

    Joined:
    Jul 20, 2005
    Posts:
    112
    Some how my low mesh rotated when exporting from lightwave. So, I just re-rotated it to match my high mesh in lightwave and exported it again and it looks like it works. Would never have known what was wrong if not for rendering the low mesh as a child for referecne.

    Thanks for the help... everything is clear now. :)