Is there an easy way to set a button on a widget to close that widget? I always thought that the “remove from parent” would do it, but apparently not! I just have a simple widget with some information, and I want the user to be able to close it when the “Ok” button is clicked. Thanks!
I recommend you setup something like this:
Put a small “Border” panel somewhere on your widget and set the Visibility to be “Hidden” by default. Inside that Border panel have 2 buttons with text labels that read “Yes” and “No” then, Create a button and add a text to it. (Make the text say “Close” or something)
On the buttons “Event Clicked” event, set the Border Panel’s visibility to Visible and then when the player clicks “Yes” just use the “Remove from Parent” event like you’ve been trying to, if for some reason it still doesn’t work use the “Remove all Widgets” event and see if that helps.
I always thought that the “remove from
parent” would do it, but apparently
not!
This definitely does work.
Show us how you do it. Perhaps you create more than one widget at the same location and they overlap.
Thanks guys. A little more context on what I’m trying to achieve. I have a BP with a sphere, a collision sphere and a widget. When the user points at that sphere the widget pops up (ideally facing the camera - I’m working on that next!!) and they need to click the button to close the widget. The remove from parent doesn’t seem to work for me, for some reason. I’m pretty dumb with blueprints, so go easy on me!
The remove from parent doesn’t seem to
work for me
Can you show how you add the widget(s) to the viewport? In an isolated scenario, removing from parent always works - there are other things at play here you’re not telling us about.
I have a BP with a sphere, a collision
sphere and a widget. When the user
points at that sphere the widget pops
up (ideally facing the camera - I’m
working on that next!!) and they need
to click the button to close the
widget.
Something tells me that you’re using a Widget Component, rather than just a widget. Can you confirm?
Yes - it is a widget component added to my "callout "blueprint. Sorry, should have been more clear. The callout BP is then added to the viewport near the product mesh. I should probably mention that I’m developing this for Magic Leap, in case that makes a difference.
Makes sense.
You can’t remove it from the parent in this instance as it’s never in a parent widget to start with, it’s a quad owned by the component. To be honest, you can simply show / hide the component instead. This is in the actor that has the widget component:
Rotating towards the player:
https://forums.unrealengine.com/development-discussion/blueprint-visual-scripting/1684887-set-widget-to-face-camera
Or, alternatively, change the Widget Component’s space from World to Screen. Not sure how this would play with augmented reality, though.
Good luck but do tell if you can’t get it to work the way you imagined.