Welcome back.
Now that we have a working attributes button, we can open the attribute menu, but we also have a close
button that doesn't currently work.
So let's quickly get that working.
So let's go into our attribute menu.
Here's our button.
I'm going to rename this to close button.
Close button.
And I'm going to check is variable there.
And now we can go into the graph and we can bind.
I'm going to use event construct to bind to its on clicked event.
So I'm going to get closed button, I'm going to get button to get that internal button widget and from
here I'm going to type a assign and we're going to assign on clicked.
So what do we want to do when the close button is clicked?
Well, we can destroy the widget.
To do that, we call remove from parent.
And that's it.
So let's go back and press play.
Let's open the attribute menu.
Let's click this button and it's closed.
But there's one problem.
We disabled the attributes button.
So the question now arises, how does the overlay re-enable the button?
I'm going to add a reroute node here before we set our position in viewport.
So that's for our attribute menu.
We're adding it to the viewport and of course we have access to it.
We could promote it to a variable.
Once we create the attribute menu, that's fine, but how are we going to know when it's been destroyed?
Well, we don't really want our attribute menu to have a dependency on the overlay because the overlay
now has a dependency on the attribute menu.
And we don't want that circular dependency.
We don't want them to depend on each other.
That would make them too tightly coupled.
I want the attribute menu to be independent of the overlay.
So the way that we can inform the overlay that this widget has been destroyed or removed is we can send
an event dispatcher that our overlay can subscribe to.
This is the blueprint version of a delegate so we can create one here in attribute menu.
Here's event dispatchers we can click plus and we can call this attribute menu closed.
So we have this attribute menu closed that we can broadcast whenever we destroy ourselves.
When we destroy ourselves, we call remove from parent and widgets.
Have an event called event destruct called when the widget is destroyed.
So when the widget is destroyed, why don't we broadcast attribute menu closed?
If I drag it out, I can select, call and make a call to this event.
Dispatcher And when this gets called, any other blueprint that subscribes a callback event to it will
have that event triggered off.
So let's compile.
Let's go back to overlay.
And as soon as we've created the menu widget, let's access that attribute.
Menu Widgets Event Dispatcher called attribute menu closed to see how we can assign to that.
So after we've set the position in viewport and all that stuff, we now have this attribute menu closed
event that we can now do something in response to the attribute menu being closed.
What do we want to do?
We want to re-enable the button so we get our attribute menu button.
Now very important.
We have to get the button widget from it.
We don't want to get attribute menu button and call set is enabled on that.
We want to get the button itself and call set is enabled on that and pass in true by checking the checkbox.
And now we're enabling that button in response to that event dispatcher broadcast.
So we'll save all and press play.
We'll open the attribute menu, click the X and our attribute button is re-enabled.
We can open and close and open and close, and that's great.
So this is the next step.
We've accomplished that now.
Yes, we are creating a new widget every single time and destroying it every single time.
An alternative would be to create the widget once and then simply hide it by setting its visibility
to false.
You could do that too.
Creating the widget dynamically is not very performance intensive, so you could really do it either
way.
If you're asking for best practices here.
Either way is okay.
I prefer this way because I just don't like a widget living in the background when it's not visible,
potentially responding to callbacks and things.
I'd rather just create it and destroy it as I open and close it.
But you could do it either way.
So this is fantastic.
We now have the attribute menu or at least the start of it and we can open and close it, but we actually
want it to show the values of our attributes.
And so we're going to be setting that up in the videos to come.
So excellent job and I'll see you soon.