Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question WebGL build behavior different than in editor.

Discussion in 'Web' started by Ollag1999, Apr 5, 2023.

  1. Ollag1999

    Ollag1999

    Joined:
    Feb 28, 2023
    Posts:
    3
    I am working through projects and missions on Unity Learn. The current project I'm working is "The Floor Is Lava." I've created a vertical obstacle course consisting of 4 platforms with primitives placed on each platform for the sphere to collide with. In Editor and Game mode, everything works great. All objects have rigid bodies, colliders, and some have physics material applied to allow the sphere to bounce off on collision and fall to the next lower platform.

    When I publish a WebGL build to Unity Play, the sphere bounces at slightly different angles than in Editor and Game mode, causing it fall off the third platform. Has anyone else encountered anything like this?
     
    Kayckbr likes this.
  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    4,330
    This can occur due to extreme delta time deviation. Specifically on WebGL it is commonly seen that the first couple frames render terribly slowly due to single-threaded asset loading, thus there's a high delta time, and with that comes deviations in physics behaviour. You may be able to observe the same behaviour in playmode if you have a script that sets Application.targetFramerate to a low value, like 1-10.

    One way to fix that is to have a loading scene, or pause affected scripts for the first couple frames, in order to have all initial processing (typically asset load) be done before the gameplay begins.
     
    Ollag1999 likes this.
  3. Ollag1999

    Ollag1999

    Joined:
    Feb 28, 2023
    Posts:
    3
    Thank you. I'm going to give your suggestions a try.