Problems hiding mouse in Widget at runtime

Hey!

Sorry, but I’m not be able to check your project personally. But I’ve been checking and you can test with a more “extreme” approach haha

You can create a function in your Widget that checks and tries to hide the widget in a couple different levels:

void YourWidget::HideMouseCursor() 
// Remember to change "YourWidget" with the name of your widget
{
    // Level 1: directly from the widget
    SetCursor(EMouseCursor::None);
    
    // Level 2: from the Player Controller, as backup in case level 1 fails
    if (APlayerController* MyPlayerController = GetOwningPlayer())
    {
        PC->SetShowMouseCursor(false);
        PC->bShowMouseCursor = false;
    }
    
    // Level 3: from the Viewport 
    if (UGameViewportClient* MyViewportClient = GetWorld()->GetGameViewport())
    {
        ViewportClient->SetMouseCursor(EMouseCursor::None);
    }
}

Then, if you call this function when pressing the button, the cursor should be hidden no matter what is controlling it. And, if it works, you can debug this to check which part of the code is actually hidden the cursor at any given moment.

Hope this helps!

1 Like