How to remove widget from viewport on button click

So as soon as I posted this. I found this little gem: UMG Tutorial .

Once this is working you add the open world node and then check in the begin play function in the gamemode cpp to check what level is loaded and have the starting widget based of that. But now there is the problem of the mouse not being captured properly

Hi I’m having a bit of trouble, I have made a simple main menu user widget and I have attached it to my player controller through c++ and handle my button inputs in blueprints. When I click on my button it takes me to the next level, However the widget persists and doesn’t get removed to my main menu widget is in the main game. I have tried removing from parent in both blueprints and c++. I have also tried removing all widgets from class in blueprints. None of these options are working. A way I think would work is changing the player controller (I have tried this in both c++ and blueprints) but can’t get this to work either.

Any help or guidence would be much appreciated

Thank you and Merry Christmas

I figured out the final solution to my question. So I used the UMG Tutorial to get the widgets all set up then in the PlayerController BeginPlay function I detect if the level is the main menu or not if it is I show the mouse cursor and set the input mode to FInputModeUIOnly. If it’s not the Main menu then I hide the mouse cursor and then set the input mode to FInputModeGameOnly.

I hope this helps anyone else with the same issue as me