PlayerController Inputs no longer work after calling UViewportClient::RemoveAllViewportWidgets();


In my code, I call GetWorld()->GetGameViewport()->RemoveAllViewportWidgets() from inside the client playercontroller. This happens as part of the server travel process in gamemode. After calling this function, the widgets before server travel are cleared but the mouse and keyboard inputs no longer work. If I disable this line, the inputs work normally again. Is there any way to restore the playercontroller inputs after clearing the widgets?
P.S: I tried setting the SetUpInPutMode with GameAndUI parameter after clearing the widgest. It made no difference.

Thank you

The problem you’re encountering is likely caused by removing all the viewport widgets, which also removes the input handlers for the mouse and keyboard. When you remove all the viewport widgets, you’re also removing the input handlers that process mouse and keyboard input and send them to the appropriate actors, such as the PlayerController.

One possible solution is to re-add the input handlers after removing the widgets. You can do this by calling the AddViewportWidgetForPlayer function on the GameViewportClient and passing in the input handlers you want to use.

Another approach to tackle this issue is to keep the input handlers active during the server travel process, by using a separate function to remove the widgets rather than calling RemoveAllViewportWidgets() and then re-adding the widgets after the travel has completed. This way, the input handlers will continue to function during the travel process.

It’s also worth checking if there’s any other part of your code that is modifying the input handling, like disabling or enabling the playercontroller inputs. You can also try adding a small delay between clearing the widgets and enabling the input handling. The delay will give time for the widgets to fully clear and not interfere with the input handling.