Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by reeverdark · Jan 19 at 12:15 AM · cursorfullscreenissueslock-cursortechnical

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?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

173 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Way to lock cursor to center and still interact with Worldspace ui 0 Answers

Lock the cursor inside the scene editor window ? 0 Answers

Cursor.lockState Not working unity 2018.2 2 Answers

How to hide cursor ingame? Please help 2 Answers

Unity 2020+ Project: Cursor Lock Requires Additional Click 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges