Hi, I have a WebGL game with a first-person point of view that locks the pointer to ensure the player can smoothly rotate the camera with their mouse. The pointer locks correctly when playtesting in the editor, when building and running locally in any browser, and on Firefox in the published/embedded form on Unity Play. However, in the Unity Play version in Chromium-based browsers, the pointer will disappear, but not lock, when clicking in the game area. This results in improper camera look mechanics (cutting off rotation at a certain angle due to the edge of the screen being reached). This occurs whether in full screen or not. Oddly, there is still a message displayed by the browser indicating that one can exit the pointer lock by pressing Esc.
After reading that browsers may require an event in order to lock the cursor, I changed the cursor lock from occurring automatically to being attached to an invisible UI.Button that covers the entire UI space. So, the current way the pointer lock is implemented is through the method in the following script, which is attached to said button and linked to its OnClick() event handler:
using UnityEngine;
using UnityEngine.EventSystems;
public class CaptureMouse : MonoBehaviour
{
public void Capture()
{
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
Debug.Log("Mouse captured");
}
}
The same issue occurs whether I use this approach or enable the pointer lock through an if InputAction.wasPressedThisFrame()-type condition in an Update() method on an arbitrary object, so it seems to me that the problem is likely with the locking functionality itself, not the condition through which it is triggered.
Why would this be working in Firefox and on local builds, but not on the Unity Play website on Chromium? Is there some sort of security approach Chromium takes that blocks proper pointer locking? Is there a way to deal with it?
If relevant, I have tried on Chrome 123.0.6312.105 and Vivaldi 7.8.3872.3 (both failing to capture pointer) and Firefox 123.0.1 (captures pointer successfully). All are running on Linux.