Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Join us on Thursday, June 8, for a Q&A with Unity's Content Pipeline group here on the forum, and on the Unity Discord, and discuss topics around Content Build, Import Workflows, Asset Database, and Addressables!
    Dismiss Notice

Lock mouse cursor

Discussion in 'Project Tiny' started by smonbrogg, Apr 6, 2021.

  1. smonbrogg


    Dec 11, 2012
    To lock and hide the mouse cursor, I'm using this code in a System OnUpdate method

    Code (CSharp):
    1. var input = World.GetExistingSystem<InputSystem>();
    2. input.SetMouseMode(PointerModeType.Locked);
    It works in Asmjs builds, a Windows dotnet build crashes as soon as the window is clicked.

    Is this a bug, or am I doing something wrong?

    I'm not sure where I should put initialization code like this. It seems strange to have initialization code in the OnUpdate method of a system that keeps running, but the RuntimeGeometry3D seems to do the same thing.
  2. Misteeps


    Dec 20, 2019
    The function just doesn't work on non-web builds.
    SetMouseMode is actually an empty function in the source code.

    It works on web builds because (from what I understand from skimming the source code), web builds use the HTMLInputSystem class inherited from the base InputSystem class and overrides SetMouseMode with actual functionality.

    It worked before using HybridInputBehaviour but ever since tiny no longer could be play tested in editor, I assume tiny no longer works with any hybrid ecs stuff.

    Again, I am not fully sure of these reasons or if it truly works or not since I haven't dove too deeply into the source code.
    If SetMouseMode is just an empty function why does it crash when clicking? No clue.

    If there's anyone who can prove me wrong and show a solution I would much appreciate.