Search Unity

cursor flickering on play

Discussion in 'Editor & General Support' started by CrazyLoafofBread, May 31, 2020.

  1. CrazyLoafofBread

    CrazyLoafofBread

    Joined:
    May 31, 2020
    Posts:
    3
    When I press play my cursor keeps flickering and can move out the play screen. I tried locking him and making it invisible with a script but nothing happened. Any help?
     
  2. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,196
    What code were you using to hide the cursor? You should include that in your reply. And are you sure that code is definitely being called? Try adding a Debug.Log statement to it to make sure it's getting executed. Also, make sure there isn't any other code in your game that's also changing mouse cursor visibility and maybe interacting badly with this.
     
  3. CrazyLoafofBread

    CrazyLoafofBread

    Joined:
    May 31, 2020
    Posts:
    3
    Yeah I am sure that my code is called but nothing happens. Also I checked for any other scripts that may run but I didnt find anything

    The code:

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class CursorLock : MonoBehaviour
    {
    // Start is called before the first frame update
    void Start()
    {
    Cursor.visible = false;
    Cursor.lockState = CursorLockMode.Locked;
    }

    // Update is called once per frame
    void Update()
    {

    }
    }
     
  4. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,196
    Well, it could be some graphics driver glitch, but that seems unlikely. What if you move that Cursor code from Start to Update, so that it keeps getting called? That's not a good thing to do in general, but I'd be curious if that helps at all. Maybe in Update you could also call Debug.Log(Cursor.visible) before doing so, to see if the cursor visibility really is internally changing back and forth.
     
  5. CrazyLoafofBread

    CrazyLoafofBread

    Joined:
    May 31, 2020
    Posts:
    3
    I tried it but it was too glitch. Like there was a delay even in the simplest move