WEBVTT

00:06.920 --> 00:08.160
Welcome back.

00:08.180 --> 00:15.050
Now that we have a working attributes button, we can open the attribute menu, but we also have a close

00:15.050 --> 00:17.330
button that doesn't currently work.

00:17.330 --> 00:20.300
So let's quickly get that working.

00:20.480 --> 00:23.420
So let's go into our attribute menu.

00:23.450 --> 00:26.200
Here's our button.

00:26.210 --> 00:29.450
I'm going to rename this to close button.

00:29.840 --> 00:31.790
Close button.

00:31.790 --> 00:33.980
And I'm going to check is variable there.

00:33.980 --> 00:37.480
And now we can go into the graph and we can bind.

00:37.490 --> 00:42.860
I'm going to use event construct to bind to its on clicked event.

00:42.860 --> 00:50.210
So I'm going to get closed button, I'm going to get button to get that internal button widget and from

00:50.210 --> 00:55.700
here I'm going to type a assign and we're going to assign on clicked.

00:56.120 --> 01:01.110
So what do we want to do when the close button is clicked?

01:01.130 --> 01:03.650
Well, we can destroy the widget.

01:03.680 --> 01:06.720
To do that, we call remove from parent.

01:09.520 --> 01:11.470
And that's it.

01:12.040 --> 01:14.020
So let's go back and press play.

01:14.020 --> 01:15.760
Let's open the attribute menu.

01:15.760 --> 01:18.730
Let's click this button and it's closed.

01:18.730 --> 01:20.140
But there's one problem.

01:20.140 --> 01:22.900
We disabled the attributes button.

01:23.080 --> 01:29.920
So the question now arises, how does the overlay re-enable the button?

01:30.980 --> 01:35.570
I'm going to add a reroute node here before we set our position in viewport.

01:35.690 --> 01:38.720
So that's for our attribute menu.

01:38.750 --> 01:42.710
We're adding it to the viewport and of course we have access to it.

01:42.740 --> 01:44.840
We could promote it to a variable.

01:44.840 --> 01:52.670
Once we create the attribute menu, that's fine, but how are we going to know when it's been destroyed?

01:52.700 --> 02:00.950
Well, we don't really want our attribute menu to have a dependency on the overlay because the overlay

02:00.950 --> 02:03.560
now has a dependency on the attribute menu.

02:03.560 --> 02:06.110
And we don't want that circular dependency.

02:06.140 --> 02:07.940
We don't want them to depend on each other.

02:07.940 --> 02:10.220
That would make them too tightly coupled.

02:10.220 --> 02:14.690
I want the attribute menu to be independent of the overlay.

02:14.780 --> 02:23.210
So the way that we can inform the overlay that this widget has been destroyed or removed is we can send

02:23.210 --> 02:26.720
an event dispatcher that our overlay can subscribe to.

02:26.720 --> 02:32.430
This is the blueprint version of a delegate so we can create one here in attribute menu.

02:32.430 --> 02:40.950
Here's event dispatchers we can click plus and we can call this attribute menu closed.

02:41.070 --> 02:49.110
So we have this attribute menu closed that we can broadcast whenever we destroy ourselves.

02:49.110 --> 02:53.550
When we destroy ourselves, we call remove from parent and widgets.

02:53.550 --> 02:59.640
Have an event called event destruct called when the widget is destroyed.

02:59.640 --> 03:04.380
So when the widget is destroyed, why don't we broadcast attribute menu closed?

03:04.380 --> 03:09.360
If I drag it out, I can select, call and make a call to this event.

03:09.360 --> 03:16.320
Dispatcher And when this gets called, any other blueprint that subscribes a callback event to it will

03:16.320 --> 03:17.730
have that event triggered off.

03:17.730 --> 03:18.990
So let's compile.

03:18.990 --> 03:20.610
Let's go back to overlay.

03:20.610 --> 03:26.010
And as soon as we've created the menu widget, let's access that attribute.

03:26.010 --> 03:34.500
Menu Widgets Event Dispatcher called attribute menu closed to see how we can assign to that.

03:34.500 --> 03:41.100
So after we've set the position in viewport and all that stuff, we now have this attribute menu closed

03:41.100 --> 03:47.870
event that we can now do something in response to the attribute menu being closed.

03:47.880 --> 03:49.020
What do we want to do?

03:49.020 --> 03:54.360
We want to re-enable the button so we get our attribute menu button.

03:54.360 --> 03:55.530
Now very important.

03:55.530 --> 03:58.350
We have to get the button widget from it.

03:58.380 --> 04:03.540
We don't want to get attribute menu button and call set is enabled on that.

04:03.570 --> 04:12.150
We want to get the button itself and call set is enabled on that and pass in true by checking the checkbox.

04:12.150 --> 04:18.180
And now we're enabling that button in response to that event dispatcher broadcast.

04:18.180 --> 04:20.850
So we'll save all and press play.

04:20.880 --> 04:26.550
We'll open the attribute menu, click the X and our attribute button is re-enabled.

04:26.550 --> 04:30.570
We can open and close and open and close, and that's great.

04:30.690 --> 04:33.810
So this is the next step.

04:33.810 --> 04:36.240
We've accomplished that now.

04:36.240 --> 04:42.390
Yes, we are creating a new widget every single time and destroying it every single time.

04:42.390 --> 04:48.240
An alternative would be to create the widget once and then simply hide it by setting its visibility

04:48.240 --> 04:49.050
to false.

04:49.050 --> 04:50.460
You could do that too.

04:50.460 --> 04:57.420
Creating the widget dynamically is not very performance intensive, so you could really do it either

04:57.420 --> 04:58.170
way.

04:58.170 --> 05:01.160
If you're asking for best practices here.

05:01.170 --> 05:02.730
Either way is okay.

05:02.730 --> 05:10.230
I prefer this way because I just don't like a widget living in the background when it's not visible,

05:10.260 --> 05:13.710
potentially responding to callbacks and things.

05:13.710 --> 05:18.030
I'd rather just create it and destroy it as I open and close it.

05:18.030 --> 05:19.470
But you could do it either way.

05:20.040 --> 05:23.070
So this is fantastic.

05:23.070 --> 05:29.850
We now have the attribute menu or at least the start of it and we can open and close it, but we actually

05:29.850 --> 05:32.970
want it to show the values of our attributes.

05:32.970 --> 05:36.900
And so we're going to be setting that up in the videos to come.

05:36.900 --> 05:40.110
So excellent job and I'll see you soon.
