Screen::SetCursorLock continuously triggers the Input::MouseMove event

Hi!

We have noticed that when the cursor lock mode is set to Locked or Clipped, the Input::MouseMove event fires continuously. Is this intended behaviour ?

Here is some code to illustrate the “problem”:

void MyCamera::OnEnable()
{
    Input::MouseMove.Bind<MyCamera, &MyCamera::OnMouseMove>(this);
}

void MyCamera::OnUpdate()
{
    if(Engine::HasGameViewportFocus()) {
        Screen::SetCursorLock(CursorLockMode::Clipped);
    }
}

void MyCamera::OnMouseMove(const Float2& mousePosition)
{
    LOG(Info, "Mouse Position: {0}", mousePosition); // continuously fired
}

Side note: I don’t really like the idea of ​​having to constantly call this portion of code into the OnUpdate method. Is it possible to do otherwise?

Thanks!

We finally found a very simple solution:

void MyCamera::OnUpdate()
{
    if(Engine::HasGameViewportFocus()) {
        // Avoid Input::MouseMove to be continuously fired!
        if (Screen::GetCursorLock() != CursorLockMode::Clipped)
            Screen::SetCursorLock(CursorLockMode::Clipped);
    }
}

We had relied on this code provided in the manual without giving it much thought. Personally, I think this side effect should be avoided :slightly_smiling_face: