- Home /
In WebGL build, Rigidbody only collides with Mesh Collider if it has previously collided with Box Collider
I have an issue where my collisions are ignored in the WebGL build, even though they work in the editor.
Here's what's happening:
Example 1: https://gfycat.com/RemoteTanAfricanharrierhawk
Example 2: https://gfycat.com/NervousDeliciousKoi
The tank GameObject is a Rigidbody with Capsule Colliders. The orange "floor" is a Mesh Collider, that white thing is a Box Collider.
If the Rigidbody 'touches' a Mesh Collider for the first time, it falls through, there is no collision.
If the Rigidbody first collides with a box collider however, the collision works, and after that it also collides as it should with Mesh Colliders.
In the Unity Editor, all collisions work as they should.
The issue is the same with both Convex and non-Convex Mesh Colliders.
My workaround for the moment is just to place an extra box collider for the Rigidbody to collide with "first", but that can't be the best solution to this. Any ideas?
Edit: I tested some more, and this also happens in an entirely empty project with just one Mesh Collider and a Rigidbody (Sphere) in it. Even more strangely, the angle of the Mesh Collider makes a difference: As soon as the mesh collider is rotated a little, the collision works as it should.
Example 3: https://gfycat.com/FormalAccomplishedBluebottle
Example 4: https://streamable.com/4y0k0
(only mesh rotation changed between these two).
In my own project, the collision also works when I rotate the "floor" mesh slightly. Is this a bug or is there something I'm missing here?
Edit 2:
Link to build: http://aliceruppert.ch/files/unity-test/index.html
Link to project folder: https://drive.google.com/open?id=0B1LEzX86fi3pTnFFOHU1UTFWelk
It seems to be an issue specific to meshes made in Blender.
Edit 3:
Another test build: http://aliceruppert.ch/files/unity-test-2/index.html
Happens both with .blend files as well as blender fbx exports, but not with Wings3D, for example.
Edit 4: The issue does not happen with an obj file exported from blender, so the problem is somewhere either in the Blender export or the Unity import...
Are you certain all normals point outwards everywhere?
Added on Twitter as well: "It seems like the rigidbodies are starting off "asleep". Hitting the box collider wakes it up while the mesh collider does not. Looking into it"
Are you sure this is only affecting WebGL builds ?
At the very least, it does not happen in $$anonymous$$ac OSX builds (as in: collisions are working normally there). That's the only other one I could try right now.
Hello. I have same problem. Standalone and Editor work, but webgl no. Standalone build: https://youtu.be/Jbb3I8Rg$$anonymous$$w8 WebGL build: https://youtu.be/PcYLOtjYqCc
I'm having the same issue, I don't know how to solve it and my game rely entirely on one mesh collider. Editor and standalone is fine, webGL broken!!! :(
I'm sorry, but the problem has not been solved yet.
Yep, I end up replacing my mesh collider with a capsule collider, not the best but it works..
did you find a fix for this? I was making a pinball game.
I'm having exactly the same issue and my game relies entirely on one mesh collider! :( I don't know how to solve it... I tried different combinations/options. Nothing. Any idea what we can try?
Answer by Schubkraft · Sep 18, 2017 at 01:19 PM
Hi, I took a look at your project and can repro this.
Can you be so nice to make a bug report from the linked project to also include the last scene you linked here with all the export options and the original blend file? Thanks!
Answer by Schubkraft · Sep 20, 2017 at 01:19 PM
Update from our end:
1) This is a precision issue that we can't easily fix for WebGL/JS. Sorry.
2) You can workaround this by changing the Fixed Timestep physics settings.
$$anonymous$$y workaround is placing a box collider for the rigidbody to collide with first, because then subsequent collisions with mesh colliders work.
Changing the Fixed Timestep did not solve the problem for me, nor would I want to simply do ALL physics calculations more often, for performance reasons.
I cannot believe that this issue has no fix, it looks like a big issue to me. Who is not using a mesh collider for their games in webGL... I'm surprised the close the bug like that. There must be a workaround or something. Should I change the shape of my object for this? I don't want to go for that drastic measure.. Should I re-open the bug to Unity?
Answer by Kjelle69 · May 30, 2020 at 11:09 AM
The trick with the "Hit a Box Collider first" really works @N-Dream-AG . :-)
I must have gone through a hundred posts about this issue before I came to this post with your random researched solution of the problem.
Answer by kkaehler · Dec 03, 2021 at 12:02 PM
The workaround "collide with box collider first" just saved my project. Huge thanks, @N-Dream-AG! I wonder how the root cause can be a precision problem.
I have to add: how this issue is handled or better not handled is deeply disappointing. It's been around for 4 years?!
Your answer
Follow this Question
Related Questions
Release Note tracking for specific platforms such as WebGL 0 Answers
Can you get a visualization of joint limits in the editor as you set them up? 0 Answers
Unity 5 project freeze after switching to WebGL 0 Answers
Compute mesh inertia tensor failed - NOT the usual problem 0 Answers
Problems with mesh collider 0 Answers