Search Unity

WebGL - Raycasting and physics positions are completely off

Discussion in 'Web' started by AHFontaine, Aug 17, 2020.

  1. AHFontaine

    AHFontaine

    Joined:
    Aug 3, 2017
    Posts:
    19
    Hi,
    I'm trying to get a first person controller to work in a webGL build. I'm using Unity 2019.4.8LTS.

    Here's my script :
    Code (CSharp):
    1.         isPaused = pauseManager.isPaused;
    2.         var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
    3.         //var ray = Camera.main.ScreenPointToRay(new Vector3(width / 2f, height / 2f, 0f));
    4.         RaycastHit hit;
    5.         if (isPaused == false)
    6.         {
    7.             if (Physics.Raycast(ray, out hit, 15.0f))
    8.             {
    9.                 var selection = hit.transform;
    10.                 if (selection.CompareTag(serialTag))
    11.                 {
    12.                     reticle.SetActive(true);
    13.                     _selection = selection;
    14.                     Debug.Log(Input.mousePosition);
    15.                 }
    I try it in the Gameview, no issues whatsoever, it does what it's supposed to do.

    However, in the WebGL build, it doesn't work but I investigated a bit more. It will find a raycast at some point but really out of the raycast's lenght, at random places.

    I gave a try and checked the mouse position when I got one. X 805, Y 65.

    Only problem :
    This element was, not only outside the screen, but also behind 3-4 different colliders.

    This is nuts!
    (Also, same behaviour on FullScreen)

    What could be the issue at this point? This doesn't seem like an error on my end at all now.
     
    Last edited: Aug 17, 2020
  2. AHFontaine

    AHFontaine

    Joined:
    Aug 3, 2017
    Posts:
    19
    Hi,
    So after checking out the console, I think I found the issue :
    It displaces my raycast origin point by either 15 units of Z forward or backwards, and 2 units up on Y axis. The only axis that is fine is the X one.

    I removed all the colliders except the ones that are selectable and I'm still getting the same result.

    Testing on PC + Mac Build, everything is ok. It's clearly a WebGL issue.

    Anybody else getting this issue?
     
  3. DevMerlin

    DevMerlin

    Joined:
    Dec 21, 2011
    Posts:
    96
    Yes, Raycasting hasn't been working here either in WebGL - everything else works well.

    This has apparently been an issue for awhile and hasn't been fixed in previous builds. I believe the issue is exactly as AHFontaine described above. When dealing with desktop web resolutions in WebGL, it isn't casting the ray correctly.

    I attempted to download the latest 2020 version, and it's an issue there as well - Version 2020.1.2f1.

    Picking something up initially works well, but then if it gets put down, somehow that throws off the ray checking. In this case, it's basic box colliders - not mesh colliders. In the meantime, I've worked out an alternative method to pick up valid items, although raycasting would make it more accurate.
     
    Last edited: Aug 18, 2020
    AHFontaine likes this.
  4. AHFontaine

    AHFontaine

    Joined:
    Aug 3, 2017
    Posts:
    19
    I suppose this will never be addressed?
    That's just a shame and asking to not use Unity for webGL anymore.
     
  5. jukka_j

    jukka_j

    Unity Technologies

    Joined:
    May 4, 2018
    Posts:
    953
    This looks like a critical bug indeed. Looking at our bug database, this issue is not known. We had one bug about computing world space positions from mouse 2D rays, but that bug has been marked fixed in 2020.1.0a15.

    A Full minimal repro testcase project as a bug report would be much appreciated!
     
  6. Nyanpas

    Nyanpas

    Joined:
    Dec 29, 2016
    Posts:
    406
    https://quakeulf.itch.io/parametric
     
  7. KamilCSPS

    KamilCSPS

    Joined:
    May 21, 2020
    Posts:
    448
  8. Nyanpas

    Nyanpas

    Joined:
    Dec 29, 2016
    Posts:
    406
    I need monetary compensation for this as I pay for the software.
     
  9. KamilCSPS

    KamilCSPS

    Joined:
    May 21, 2020
    Posts:
    448
    I don't understand... you want Unity to pay you to help report a bug?
     
  10. Nyanpas

    Nyanpas

    Joined:
    Dec 29, 2016
    Posts:
    406
    I am a Pro-user. I pay to use their product. They are not delivering what I am paying for. Why should I spend my own time on something they should be able to address by looking here?
     
  11. KamilCSPS

    KamilCSPS

    Joined:
    May 21, 2020
    Posts:
    448
    That's a big assumption. How do you know they can find the root issue just by looking at a compiled build? How long you think this is going to take them vs getting a repro project? Time not spent fixing other bugs.

    Also, no. You're wrong. You paid for a software, and software is not perfect. Do you ask a game developer to pay you for bugs in their games? Heck, will YOU be paying your own customers to report bugs in what you're developing? Of course not.

    I get you're frustrated by a bug (we all are, we are Devs) but all I was doing is helping you direct your energy where it will be the most efficient to resolve this quickly.
     
  12. Nyanpas

    Nyanpas

    Joined:
    Dec 29, 2016
    Posts:
    406
    By replying to me you aren't helping either.
     
  13. AHFontaine

    AHFontaine

    Joined:
    Aug 3, 2017
    Posts:
    19
    So you just post a compiled version in an issue I raised, without any explanations of what exactly is the problem in your build, and is currently arguing that you should get a refund?
    Thanks for not helping to the general cause, I guess?
     
    KamilCSPS likes this.
  14. jukka_j

    jukka_j

    Unity Technologies

    Joined:
    May 4, 2018
    Posts:
    953
    I appreciate the sentiment, and I believe that you should be able to negotiate with licensing about refunds if you run into a critical bug that is preventing your use case. If Unity is not delivering, it is not delivering, and you have a solid case.

    However refunds are not something that we can help you on this forum. If you do wish to proceed with that, I'm sorry to hear :( But in that case, please contact customer support for such dialogue, they should be able to help you out.

    Sometimes an issue is something that can be triaged directly by looking at a build, but other times (and in this case) that sadly does not seem to be the case. I tried running the build, and you can find my experiment here: http://clb.confined.space/dump/itch_io_parametric.mkv . Honestly, I am not sure what I should be looking for here. Is the flickering appearance of the house the bug here? Or the location it spawns to? The green dots seem to appear properly under the mouse cursor. Right-click did not seem to do anything. Middle-click did remove all the dots.

    In a case like this, where hypothetically a raycasting math bug occurs (assuming without knowing for sure where the issue would like), it is not possible to debug the issue without a reduced test case project at hand, since fixing the issue will require rebuilding the Unity engine with custom debug code, and then rebuilding the test project against that custom Unity engine build (and typically iterate on such workflow to zoom in to the root cause).
     
  15. AHFontaine

    AHFontaine

    Joined:
    Aug 3, 2017
    Posts:
    19
    Hi Jukka,
    Just wanted to say that I didn't send a minimal repro and a bug report yet because the project I worked on decided to remove it altogether. This being said, I remember that my issues was not reproducible in a situation where you had one cube, no player, and just clicked on the cube itself.
    The big difference that comes to mind is that the issue happens when I'm using a First-Person Controller, starting on a non 0,0,0 world position.
    Wondering if this helps. If not, I'll try to find a moment to have a minimal repro. Note that I'm currently using 2019 LTS.
     
  16. Nyanpas

    Nyanpas

    Joined:
    Dec 29, 2016
    Posts:
    406
    This was a really critical situation with a potential customer involving a few big tech companies. I was desperate and disappointed that things I took for granted in previous versions of Unity as well as UWP did not work in WebGL.

    I have since managed to resolve the situation, but some of these things should really be unit tested internally at Unity3D. There are lots of good automated testing tools out there and these things can be avoided.
     
  17. BangingRocks

    BangingRocks

    Joined:
    Jun 19, 2018
    Posts:
    4
    Nyanpas, can you share anything about the resolution? I'm encountering what I think is the same issue with Raycasting anomalies in a WebGL build from Unity 2019.4