Skip to content

Unity - Common Issues

This page contains issues that you may encounter in Unity WebGL games, and potential fixes to them.

MacOS rendering issues

If you are using URP, you may encounter rendering issues on Mac (black meshes, or flickering meshes).

A potential fix is to disable Depth Priming Mode in Universal Renderer Data.

Universal Renderer Data

WebGL random abnormal high values in mouse input

We have encountered some games randomly registering an abnormally high mouse input when reading the mouse movement. If your game is also affected by this issue, you can use the following script:

using UnityEngine;

public class WebGLMouseInput : MonoBehaviour
{
    public float diffThreshold = 100f;
    public float absMax = 800f;
    public int maxConsecutiveSpikes = 2;

    private float _prevX,
        _prevY;
    private int _spikesX,
        _spikesY;
    private float _outX,
        _outY;

    void Update()
    {
        float dx = Input.GetAxisRaw("Mouse X");
        float dy = Input.GetAxisRaw("Mouse Y");

        _outX = Filter(dx, ref _prevX, ref _spikesX);
        _outY = Filter(dy, ref _prevY, ref _spikesY);
    }

    private float Filter(float cur, ref float prev, ref int spikes)
    {
        if (Mathf.Abs(cur) > absMax || Mathf.Abs(cur - prev) > diffThreshold)
        {
            spikes++;
            if (spikes >= maxConsecutiveSpikes)
            {
                prev = 0f;
                spikes = 0;
            }
            return 0f;
        }

        spikes = 0;
        prev = cur;
        return cur;
    }

    public float GetDeltaX() => _outX;

    public float GetDeltaY() => _outY;
}

Attach it to an object in your scene, and obtain the mouse input via the GetDeltaX or GetDeltaY methods.