WEBVTT

00:07.160 --> 00:07.760
All right.

00:07.760 --> 00:15.920
So now that we know when an effect is applied and we have the ability to get the asset tags for that

00:15.920 --> 00:21.050
effect and we want those tags to be broadcast over to the widget controller.

00:21.050 --> 00:22.470
We need a delegate.

00:22.490 --> 00:26.660
So I'd like to make a delegate for broadcasting the asset tags.

00:27.080 --> 00:32.450
Let's go into aura ability system components and make that delegate.

00:32.900 --> 00:37.250
Now, I don't plan on binding this from Blueprint.

00:37.400 --> 00:39.940
Our widgets aren't going to bind to this delegate.

00:39.950 --> 00:43.820
It's our widget controller that's going to bind to this delegate.

00:43.820 --> 00:50.060
So what I'm going to do is declare a multicast delegate.

00:50.090 --> 00:52.130
That's not dynamic.

00:52.930 --> 00:55.420
And it's going to have one param.

00:56.290 --> 01:04.930
And that param is going to be the asset tag or if we'd like the gameplay tag container with all the

01:04.930 --> 01:07.390
asset tags, it's really up to us.

01:07.510 --> 01:16.150
Now I'm going to call this F effect asset tags and our single parameter.

01:16.180 --> 01:20.890
Again, it could be a gameplay tag or it could be a gameplay tag container.

01:20.920 --> 01:23.910
I'm going to use gameplay tag container.

01:23.920 --> 01:27.550
So we're going to have a gameplay tag container.

01:27.760 --> 01:32.020
We'll go ahead and make it a const f gameplay tag container reference.

01:32.290 --> 01:39.430
And as we've seen with declare multicast delegate, we don't put the name of this parameter.

01:39.430 --> 01:45.160
We don't say comma followed by tag container or anything like that.

01:45.160 --> 01:55.100
But sometimes what I've seen and this can be a little helpful is making a comment here, an inline comment

01:55.280 --> 02:01.400
to sort of hint about what this is so we could say asset tags.

02:02.210 --> 02:09.170
And so even though that this comment does nothing to the code, it tells us when we look at it, that

02:09.170 --> 02:10.790
that's what this tag container is.

02:10.790 --> 02:12.200
It's the asset tags.

02:12.230 --> 02:15.890
Now, our ability system component needs this delegate.

02:15.890 --> 02:21.650
It needs to be able to broadcast the delegate and our widget controller needs to be able to bind to

02:21.650 --> 02:21.800
it.

02:21.800 --> 02:23.540
So we need to make this public.

02:23.540 --> 02:30.920
So in the public section, we're going to have our effect asset tags and we're going to call this effect

02:30.920 --> 02:34.160
asset tags and we're going to broadcast it.

02:34.160 --> 02:40.460
Now, what we can do if we like, is we can broadcast it here, in effect applied because we know this

02:40.460 --> 02:44.570
gets called and we have our asset tags, we have the tag container.

02:44.570 --> 02:55.540
So all we need to do here is just say effect asset tags, dot broadcast and pass in tag container just

02:55.540 --> 02:56.410
like that.

02:56.560 --> 03:05.020
And then any class who binds to our effect asset tags delegate will receive a tag container filled with

03:05.020 --> 03:06.340
the asset tags.

03:06.490 --> 03:07.720
Pretty simple.

03:07.810 --> 03:15.280
So really quickly to test this out, what we can do is we can go into our overlay widget controller

03:15.280 --> 03:18.670
and bind to effect asset tags if we like.

03:19.330 --> 03:20.980
So let's do it.

03:20.980 --> 03:26.350
We'll go into UI widget controller and overlay widget controller.

03:26.590 --> 03:27.550
But you know what?

03:27.550 --> 03:30.520
I'm going to go into the CPP file directly.

03:31.610 --> 03:39.500
So overlay widget controller TCP and here in bind callbacks to dependencies, I'd like to get our ability

03:39.530 --> 03:46.400
system component and we know that this is a ability system component, but we want the aura ability

03:46.400 --> 03:47.530
system component.

03:47.540 --> 03:54.320
So I'm going to cast to you aura, ability, system component, our ability system component.

03:54.320 --> 04:00.830
And using this, I'm going to get that F effect asset tags called effect asset tags.

04:01.250 --> 04:07.580
Now we know if we're going to bind to this delegate that we need a callback function, right?

04:07.610 --> 04:08.960
Well, not necessarily.

04:08.960 --> 04:14.710
If we hit Dot, we have a lot of options here and one of them is to add a lambda.

04:14.720 --> 04:18.290
Now, a lambda is an anonymous function.

04:18.290 --> 04:19.550
It doesn't have a name.

04:19.550 --> 04:21.770
It doesn't get declared anywhere.

04:21.770 --> 04:23.660
It's not a member function.

04:23.660 --> 04:25.790
It's just a function.

04:25.790 --> 04:33.980
And add lambda lets us define right here in the parentheses whatever functionality we want.

04:34.010 --> 04:37.010
Called in response to the delegate broadcast.

04:37.160 --> 04:39.410
A lambda looks like this.

04:39.410 --> 04:43.400
I'm going to hit enter a couple times and just put it right here.

04:43.400 --> 04:50.180
In fact, I'll go ahead and put my semicolon there and right here this is inside the parentheses to

04:50.180 --> 04:53.510
add Lambda ad lambda requires a lambda.

04:53.510 --> 04:55.670
We're going to make a lambda here.

04:55.670 --> 05:03.680
So first we put square brackets, then we put parentheses and then we put curly brackets.

05:04.070 --> 05:08.180
Okay, so this is the signature for a lambda.

05:08.180 --> 05:13.490
But if we bind anything to a delegate, it needs that signature.

05:13.490 --> 05:18.830
It needs the signature of a function that can take an gameplay tag container.

05:19.100 --> 05:22.640
Well, this lambda has parentheses.

05:22.640 --> 05:25.640
That's where the input parameter list goes.

05:25.640 --> 05:36.080
So we can put a const f gameplay tag container reference and we can call this asset tags.

05:36.430 --> 05:38.180
Doesn't matter what we call it.

05:38.180 --> 05:42.590
So now we have a lambda which is an anonymous function.

05:42.590 --> 05:50.600
And when the broadcast happens for this delegate, this lambda will be called and it has an input parameter

05:50.600 --> 05:53.900
called asset tags, it will receive that from the delegate.

05:53.900 --> 06:01.850
And what happens when it gets called whatever we put in the body here in our curly brackets, I'm going

06:01.850 --> 06:06.020
to put them on a new line to make this a little easier to read.

06:06.050 --> 06:08.530
And we can define what happens here.

06:08.540 --> 06:11.330
So what do we want to happen?

06:11.330 --> 06:11.650
Right.

06:11.660 --> 06:19.370
Because we've just now bound a lambda to affect asset tags on the ability system component.

06:19.400 --> 06:23.300
Well, why don't we just print a debug message and make sure it works?

06:23.300 --> 06:30.710
So back here in aura ability system component, I think we're done with this debug message, but what

06:30.710 --> 06:34.680
I'd like to do is copy it or rather control X to cut it.

06:34.680 --> 06:40.830
So now our ability system component is not doing any debug messages, it's just broadcasting a delegate.

06:40.830 --> 06:47.100
But now our widget controller has a lambda that will fire off in response to that delegate.

06:47.100 --> 06:52.920
Well, I'm going to control V right here and we can paste this code in where we can loop through the

06:52.920 --> 06:53.970
tag container.

06:53.970 --> 06:58.500
Now here inside the lambda, it's going to receive asset tags.

06:58.500 --> 07:00.000
That's the tag container.

07:00.000 --> 07:02.340
So that's what we have to loop through here.

07:02.340 --> 07:09.630
So we have a for loop looping through all the tags in the asset tags container and we don't need this

07:09.630 --> 07:10.530
comment.

07:11.190 --> 07:14.160
And well, we know what these two lines do.

07:14.160 --> 07:21.810
They take each tag in asset tags and add an on screen debug message basically the same thing as we were

07:21.810 --> 07:22.860
doing before.

07:23.070 --> 07:29.550
So the difference here now is that the ability system component will broadcast this delegate in response

07:29.550 --> 07:32.430
to having any effect applied to it.

07:32.580 --> 07:39.330
And it's going to send that tag container and then it's the widget controller that's going to parse

07:39.330 --> 07:39.750
the data.

07:39.750 --> 07:43.860
It's going to loop through the tag container and print it all to the screen.

07:43.860 --> 07:48.960
So if we can run this and it works, then that's actually really cool, right?

07:48.960 --> 07:55.500
Because this means we don't have to go and declare callback functions for all the delegates that we

07:55.500 --> 07:56.760
want to bind to.

07:56.790 --> 07:57.390
Right.

07:57.390 --> 07:59.940
This makes things a little bit simpler.

08:00.030 --> 08:04.770
I mean, look at all these callbacks we had to make for all of these delegates.

08:04.770 --> 08:07.490
What if we could just use lambdas for all of those?

08:07.500 --> 08:09.600
Well, let's make sure this works first.

08:09.600 --> 08:10.080
Okay.

08:10.080 --> 08:15.630
Let's go ahead and hit debug and see if we can get some messages printed to the screen.

08:15.900 --> 08:16.440
Okay.

08:16.440 --> 08:17.400
So we're back.

08:17.400 --> 08:23.040
I'm going to go ahead and let it open up my gameplay effects just to make sure our potion mana gameplay

08:23.040 --> 08:30.240
effect has two tags in its asset tags potion Heal has one and Crystal Heal has one.

08:30.240 --> 08:31.140
So let's press.

08:31.350 --> 08:33.600
Play and get a crystal and look at that.

08:33.600 --> 08:34.670
It's working.

08:34.680 --> 08:37.680
Our lambdas are working.

08:38.360 --> 08:39.590
How about that?

08:39.980 --> 08:41.240
This is great.

08:41.270 --> 08:45.860
Now, if you're skeptical, you can place a breakpoint here.

08:46.010 --> 08:47.470
So I got a breakpoint.

08:47.480 --> 08:50.150
I'm going to press play and pick up the potion.

08:50.150 --> 08:53.660
And look, the breakpoint works even in a lambda.

08:53.660 --> 09:01.550
So a lambda is one of those tools in C plus plus that we have at our disposal that allows us to kind

09:01.550 --> 09:07.430
of avoid having to create a bunch of member functions, especially for things that are simple, right?

09:07.430 --> 09:13.730
If we're going to bind a callback to a delegate and it's pretty simple, there's really no point in

09:13.730 --> 09:15.980
creating a whole callback function for it.

09:16.010 --> 09:20.780
A lambda is cleaner sometimes and it's also kind of fancy, right?

09:20.780 --> 09:21.740
It's kind of cool.

09:21.740 --> 09:26.180
So now that we know how to do that, we just have one more tool in our tool belt.

09:26.180 --> 09:31.700
And if you already knew about Lambdas, maybe you've been using this already, then you already have

09:31.700 --> 09:32.900
this tool in your toolbox.

09:32.900 --> 09:37.370
And I think that's great that you've been taking advantage of it.

09:37.700 --> 09:39.500
So excellent job.

09:39.500 --> 09:42.260
We're now one step closer to our goal.

09:42.260 --> 09:48.860
We have those asset tags here in our widget controller overlay widget controller.

09:48.890 --> 09:54.500
The next step is to get them to the widgets themselves so we can do that next.

09:54.500 --> 09:58.340
In the meantime, I'm going to go ahead and hit the stop button.

09:58.430 --> 10:02.990
We're done with this and I'll see you in the next video.
