Cursor.lockState not working on my pc, but the build works for others?
Hi all. I have a somewhat strange situation. Maybe it's a fringe case, but i'm building an fps on my desktop windows system with more than 1 monitor, and... i will say this explicitly... the Cursor.lockState does not work. At least it does not work on my pc. I will explain what i mean in detail, but first, this is the code im using.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CursorController : MonoBehaviour
{
void Start()
{
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
}
void Update()
{
Debug.Log(Cursor.lockState);
if (Input.GetKeyUp(KeyCode.LeftAlt))
{
if (Cursor.lockState == CursorLockMode.Locked )
{
Cursor.lockState = CursorLockMode.None;
Cursor.visible = true;
Debug.Log("Nolock key was released.");
}
else if (Cursor.lockState == CursorLockMode.None)
{
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
Debug.Log("Nolock key was set.");
}
}
}
}
Ok so. When in the editor, or as a build, with the cursor visibility on or off, the cursor it still completely free and will leave the screen. With the cursor hidden and the lock on as per the code above, the cursor will still move outside the game port windows and will highlight things like objects in the hierarchy or editor UI buttons. This points out that the cursos for whatever reason does not lock at all.
Now here's the kicker. I got my friend to make a test build of the current project in case there was some conflict somewhere. Only it worked... it was completely fine his end. The code worked. Not completely convicted, i use my laptop and repeat the process, i even create a new project on both systems with the above code and as it happens, on the laptop, it works... or at least when i toggle between lock and unlock, the cursor is alway in the centre of the screen when it no longer hidden (reset).
I've looked into all the methods i could, including OnApplicationFocus, but nothing has worked.
On a side note i do have to use Dual Monitor tools as this behaviour persist with actual games and fullscreen applications as well. Elite Dangerous and Farming Simulator 19 being good examples, as the cursor will always run off screen. Thinking that there may be some conflict here, i have tried it without but again no dice, the cursor is running off to the next screen or in general just not locked at all.
My system is a windows 10 on the latest update as of new years 2022. Hardware wise, i'm on an Intel 9th gen i7, 32gb ram, on an Asrock ITX board, and an MSI 4095MB NVIDIA GeForce RTX 2080 super. Most of these are a few years old now, but i'm wondering if i have some strange environment variable? I am also on 3 monitors with my setup. 2 generic Benq and a Huion drawing tablet.
To be honest im at a loss as to why my desktop is like this, and would like to ask for suggestions as to what might be the issue?