Search Unity

Mesh colliders not working! I tried everything.

Discussion in 'Physics' started by Ryan_3D, Dec 13, 2018.

  1. Ryan_3D

    Ryan_3D

    Joined:
    Feb 6, 2015
    Posts:
    34
    Please help me i am getting really pissed. I wasted 2 hours in trying to figure out what is going on. My mesh colliders just don't work. My trees also have mesh colliders, they don't collide with my player. My raycast doesn't detect my enemy's mesh colliders when i am shooting at them. BUT, the box collider is working? I tried putting box collider and it seems to be working. However, box collider is not what i need. I haven't messed with layers, tags or any other project settings. I tried disabling all the scripts in my scene, nothing worked. I am so mad for i wasted so much time not being able to solve so simple problem. It's pointless making screenshot from my project. It's a new project that has only 5 models imported to it, brand new project with a simple character controller. Any idea what may cause this problem? I searched trough all google results, i only found useless answers that didn't work and wasted my time even more. When i started my project i expected to find issues while i am doing programming, not while doing simple S*** like this. Excuse me for my bad tongue, i am so mad.

    Box colliders work, mesh colliders don't work.
    - there are no rigidbodies attached to any of the gameobjects except the player.
    - i tried testing while all the scripts were disabled and the mesh colliders still didn't work.

    Please help me.
     
    unity_dhedXB4jnllQyA likes this.
  2. Ryan_3D

    Ryan_3D

    Joined:
    Feb 6, 2015
    Posts:
    34
    Omfg i am going crazy over this.
     
    CandraWi likes this.
  3. Ryan_3D

    Ryan_3D

    Joined:
    Feb 6, 2015
    Posts:
    34

    FORGOT TO MENTION
    I am using unity 5. My laptop is 32 bits so i am unable to run the newest version.
     
    Last edited: Dec 13, 2018
  4. SparrowGS

    SparrowGS

    Joined:
    Apr 6, 2017
    Posts:
    2,536
    Look at the mesh collider, there's a property call "Mesh".

    'Nuff said. ;)
     
  5. Ryan_3D

    Ryan_3D

    Joined:
    Feb 6, 2015
    Posts:
    34
    Do you think that for 4 hours(6 actually) i didn't saw that option? The thing is, that my enemy is animated and that mesh doesn't fit. There is no mesh that i can put in that option.
     
  6. Ryan_3D

    Ryan_3D

    Joined:
    Feb 6, 2015
    Posts:
    34
    To be more clear....

    EDIT: Also, my trees are generated by an asset... so they don't have mesh either XD can you offer some other solution please ? lol

    Okay i go to get some sleep now. My brain burned all of my calories today. Its so pathetic that this simple thing managed to kill 6 hours of my life. It will kill even more XD
     
    Last edited: Dec 13, 2018
    CandraWi likes this.
  7. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    2,512
    Mesh collider needs a mesh to check collisions against. No mesh, no collisions. Is that simple. Without mesh, the MeshCollider component does nothing.

    It's up to you to provide a collider to the mesh collider components. It may be the same mesh used for the visual geometry, or a simplified mesh that approximates the shape and works good enough. FPS typically use capsule colliders for this.
     
  8. Ryan_3D

    Ryan_3D

    Joined:
    Feb 6, 2015
    Posts:
    34
    Allright, understood. But how it is that in the past i was able to just add the mesh collider component without adding any additional mesh stuff? I'm confused af.
     
  9. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    2,512
    Surely you were adding the mesh collider to the object containing the visual mesh. In that case the component takes the visual mesh as collision mesh.
     
    Ryan_3D likes this.
  10. unity_7ji8piaqGVfRfg

    unity_7ji8piaqGVfRfg

    Joined:
    Feb 25, 2020
    Posts:
    2
    I have a mesh attached to the collider but i'm facing the same problem...
    please help i have tried evrything
    ..............
    please HELP!!!
     
  11. unity_7ji8piaqGVfRfg

    unity_7ji8piaqGVfRfg

    Joined:
    Feb 25, 2020
    Posts:
    2
    This is the mesh attached to my model...
     

    Attached Files:

  12. m_nejatish

    m_nejatish

    Joined:
    Mar 16, 2020
    Posts:
    2
    I had the same problem but mine solved in this way: you should add a rigid body to your object and make it kinematic. It would work like a charm.
     
  13. mushroomseasonisopen666420

    mushroomseasonisopen666420

    Joined:
    Apr 23, 2020
    Posts:
    16
    Yeah, this is driving me mad. Not sure what I'm doing wrong, but my mesh isn't added by default, and it's pretty askew....

    I swear there's some little trick I used to enable my mesh last time; but I don't remember my collider ever being this displaced.
     

    Attached Files:

  14. MarquesGabriel

    MarquesGabriel

    Joined:
    Jun 11, 2020
    Posts:
    1
    I have the same problem. I'm going crazy. Here, the meshes goes on the wrong angle... or wrong position. :(

    Like this:

    upload_2020-6-15_18-0-8.png
     
  15. tjmaul

    tjmaul

    Joined:
    Aug 29, 2018
    Posts:
    467
    Did you add the mesh collider to the GameObject that also holds the MeshFilter? If not, the game object that you're added the mesh collider to should have the same position, rotation and scale as the one rendering the mesh.

    A mesh doesn't magically appear in the "right" position. It's transformed via the transform component. If you add a mesh collider to a game object that has a different transform than the game object rendering the mesh, their positions will be different.
     
    BigDenni likes this.
  16. koirat

    koirat

    Joined:
    Jul 7, 2012
    Posts:
    2,074
    May I ask why you need a mesh collider on a character ?
    You do know it is not going to be animated with your character ?
    But stay in this T pose forever .
     
    bugfinders, arkano22 and tjmaul like this.
  17. mohamadthaier2

    mohamadthaier2

    Joined:
    Aug 4, 2020
    Posts:
    4
    You don't have to make a perfect collider
    just make some capsules or boxes
     
  18. poulpoapplications

    poulpoapplications

    Joined:
    Feb 21, 2020
    Posts:
    3
  19. Workshoot

    Workshoot

    Joined:
    Feb 7, 2021
    Posts:
    1
    This may be old, but I figured the answer in my case was that I had "Is Trigger" checked on the item I wanted to detect collision with. Soon as I unchecked this option, collisions started to work.
     
  20. guinunez

    guinunez

    Joined:
    Apr 15, 2015
    Posts:
    7
    So, I had a similar problem:

    1- You need the mesh to be convex in order to work and enable the "convex" attribute in the variable
    2- If your mesh is not convex, you have to divide it into several convex meshes, this one was really hard, I used Blender and this tool: https://github.com/andyp123/blender_vhacd but be careful, it is no longer maintained and it won't work on the latest blender version, some dude uploaded a pull request that is not merged, but it worked: https://github.com/andyp123/blender_vhacd/pull/8 Follow the first page instructions carefully but with the pull request's script and you will be fine. I had to max out all the V-HACD parameters for my mesh.
    3- unity only accepts up to 256 triangles for a mesh collider, so decimate if needed
    4- import the meshes into unity, add the mesh collider to all of them, and mark the convex attribute
    5- At this point, Unity still had the colliders wrong, very wrong, I had to open the "cooking options" property, set that to "None", then disable "convex" and re-enable it again.

    Now it worked as I need it
     
  21. NaroXo

    NaroXo

    Joined:
    May 9, 2019
    Posts:
    8
    So even if this post is very old, but I still want to mention this because I haven't seen anyone mention this in this thread except @koirat. You do not use a Mesh Collider for Character or almost anything complex then a Landscape, because its way too much detail that the player will never notice, and for most PCs to handle.
    Keep in mind that every corner of a collider needs to be calculated every frame, so fewer details = better performance
    Even games like Dark souls, wich has one of the most detailed Character collisions i know, they still use basic formes like capsules or boxes for the limbs and bodys and still have enaught detail that you can roll betwene an enemys legs.

    so TL: DR, for most cases just uses a simple Capsule Collider or if you really need the detail, every body part a basic collision shape
     
    Augustinas-Simkus likes this.
  22. PG13park

    PG13park

    Joined:
    Apr 25, 2022
    Posts:
    18
    What if VR? then what );
     
  23. DucaDiMonteSberna

    DucaDiMonteSberna

    Joined:
    Jan 18, 2018
    Posts:
    79
    We really need the possibility to set a mesh collider position and scale like the other colliders. And all colliders need also to have their rotation settable.
     
  24. tjmaul

    tjmaul

    Joined:
    Aug 29, 2018
    Posts:
    467
    You already have this possibility: Just add the mesh collider to a child gameobject and adjust position, rotation and scale