Removing a widget from viewport

I am trying to remove a UI widget from viewport using a RemoveFromViewport node. But something wierd happened.

After the function executed, the mouse cursor appeared and blocked all keyboard inputs even in the launch mode. I must left-click the mouse to enable the keyboard inputs. Anyone knows that is this a bug or I should try another way to do this?

  • Change your Event Type to a Keypress event
  • Create a Boolean variable WidgetIsActive default it to falce
  • Create an IF Branch node
  • On the True branch, add a Remove From Viewport node (you may need to uncheck the context toggle to get this to show up)
  • Set the target variable to your widget
  • Set the boolean to false.
  • Connect the Add to Viewport up to the “True” output of the If branch, and remove the delay and Remove Viewport nodes you have there.

Enjoy,
Tony

See my answer below for how to fix, but I wanted to explain what is happening here. “Event Begin Play” fires immediately when the game starts and makes the call to create the widget. Immediately after that, it adds it to the view port, then waits 10 seconds and destroys it.

However, you have nothing mapped here to happen on mouse click or keyboard event. By default, when you click the play button you need to click once inside the screen in order to take control of the in-game actor.

You might also want to consider sending the widget to a variable after you create the widget, so that you can call it again later.

Sorry Tony. It seems you misunderstanded my problem. The problem is not about the beginplay time. It’s about the Removefromviewport node. I want to enable the widget when the game begins and disable it when the character dies. Using the RemoveFromViewport node cause the mouse cursor appear again whenever I disable it. In my game there’s no character controller blueprint for the player character so the mouse cursor should not appear. Is there any other way to disable a UI widget whenever I want to?

I do not think (I’m not 100% certain) that UE4 removes mouse functionality simply because there is no character there. The reasoning behind that assumption is pretty simple. If it did, you would not be able to use any start game menus prior to character spawn. Check here:

Widget Documentation

To supplement the nodes above, you may
want to Enable/Disable the Mouse
Cursor from being displayed. You can
do so by using the Set Show Mouse
Cursor node. Drag off a Get Player
Controller node, then use the Set Show
Mouse Cursor node and check it to True
or False to Display or Hide the Mouse
Cursor.

And here: Setup Input

Thanks Tony! After I tried different ways, there still some problems. My game simply use the PlayerStart to spawn my character and then the widget I create is in the character blueprint instead of the level blueprint. So it will execute after my character spawned. Everything is OK when I begin the game and the inputs are good. After my character died, I did not destroy the actor. I play an animation instead and before that I disable the UI first. The screen shot above is just an instance for testing that whenever I disable the UI in whatever event the mouse cursor appeared and all my inputs are disabled just like jump out from the game.:frowning:

Awesome. Glad it worked! Be sure and set the question to answered. Good luck with the rest of your project.

sorry it did not work…I was just sleepy coz it’s midnight here. I run the game several times and found that the cursor is not shown indeed but the inputs are still blocked…