Search Unity

Lock mouse cursor

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

  1. smonbrogg

    smonbrogg

    Joined:
    Dec 11, 2012
    Posts:
    12
    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?

    https://docs.unity3d.com/Packages/com.unity.tiny@0.32/api/Unity.Tiny.Input.PointerModeType.html

    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

    Misteeps

    Joined:
    Dec 20, 2019
    Posts:
    2
    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.
     
unityunity