Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  2. Ever participated in one our Game Jams? Want pointers on your project? Our Evangelists will be available on Friday to give feedback. Come share your games with us!
    Dismiss Notice

Raycasts do not register on some MeshColliders in WebGL (2017.2-.4 regression)

Discussion in 'Editor & General Support' started by AmbOcclusion, May 21, 2018.

  1. AmbOcclusion


    Sep 17, 2012
    We are having issues with raycasts in 2017.4 on WebGL where they will not register on some objects with MeshColliders. It's not consistent and probably affects 20-40% of objects in our entire project.

    • We are using RaycastAll but RaycastNonAlloc does not fix it.
    • The MeshColliders are not convex but setting them to convex fixes some of them but causes issues with some other % of objects that didn't have problems in other scenes.
    • Some of these objects are inside of other colliders, but not all of the objects exhibiting the issue are inside of another object.
    • The issue crops up in WebGL but not in the editor. The MeshColliders return correctly 100% of the time in-editor

    The issue is reported here but was dismissed. I can confirm that the 2018.2 beta does not exhibit the problem but we unfortunately cannot move to a beta release for a live product.

    I cannot share a copy of the project or rip out the problem bits due to it being the company's property but I can work with someone from Unity to sort this out.
    robertes likes this.
  2. MoinTom


    May 8, 2015
    We experienced the same issue after upgrading to 2017.4.3f1. We had to downgrade to 2017.3.0p4 for our last deployment in order to "fix" it. Unfortunately i am also not able to share the source code due to it being company's property.
    Last edited: May 24, 2018
    robertes likes this.
  3. shaselwimmer


    May 8, 2018
    I'm experiencing this issue using the latest version of Unity on Mac (2018.1.5f1). I have a sphere that is covered in a mesh representing simple blocks. When I mouse-over with a coded RayCast in the editor, everything works fine - the blocks are detected as hit. But when I then transfer to WebGL, huge numbers of the blocks fail to pick up the raycast. I compile to Mac desktop app and everything works fine again.

    I suspect it has something to do with the floating point handling in WebGL (see this for a related issue:

    When I maintain my camera at 0,0,0, everything works great. But when I then rotate around an object - causing the camera position to become tiny floating point values, things go wrong.

    Really need a fix for this as it renders my application unusable in WebGL.
    addiadriano likes this.
  4. JimStoy


    Oct 18, 2013
    i'm experiencing this problem too on WebGL build. works fine for other build.
    Here, a video for exemple :

    Simple scene with raycast on a maskLayer (white plane)
    Code (CSharp):
    1.     void Update () {
    2.         RaycastHit hit;
    3.         Ray ray = mainCamera.ScreenPointToRay(Input.mousePosition);
    4.         var floorLayer = LayerMask.GetMask("testFloor");
    6.         if (Physics.Raycast(ray, out hit, 1000f, floorLayer))
    7.         {
    8.             Cube.transform.position = hit.point;
    10.         }
    11.         Debug.Log("distance: " + hit.distance + " |point: " + hit.point + " |name:" +;
    12.     }
    I tried to truncate camera position for remove tiny float but no change
  5. JimStoy


    Oct 18, 2013
    after upgrade to unity 2018.2.2f1, problem solved !