WEBVTT

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

00:08.120 --> 00:15.680
So now that we know that our ability system component has some inherited delegates, let's see what

00:15.680 --> 00:19.640
happens when we bind to one of these and apply a gameplay effect.

00:19.670 --> 00:24.200
Now I'm interested in on gameplay effect applied delegate to self.

00:24.200 --> 00:30.740
This seems like a pretty nice one and we need to know what the function signature should be for a callback

00:30.770 --> 00:32.690
that can be bound to this.

00:32.690 --> 00:40.160
So I'm just going to right click on its type, go to declaration or usages and here it is delegate for

00:40.160 --> 00:46.460
when an effect is applied and we see that it takes an ability system component pointer, a gameplay

00:46.460 --> 00:50.180
effect spec and an active gameplay effect handle.

00:50.180 --> 00:55.250
So in other words, when the ability system component broadcasts this delegate, it's going to pass

00:55.250 --> 01:00.560
this information in and we'll be able to receive that, which is actually pretty nice.

01:00.680 --> 01:07.880
Now if you've seen a declare multicast delegate signature, you might have seen sometimes that these

01:07.880 --> 01:15.410
macros have the parameter names, but in declare multicast delegate, you can just have the types Without

01:15.410 --> 01:19.730
the names there, that's totally fine and that's why we have this here.

01:20.000 --> 01:25.280
So we know that our callback needs to have these three input parameters.

01:25.280 --> 01:26.690
It needs this signature.

01:26.690 --> 01:33.440
So let's make a callback for our ability system component that we can bind to the delegate.

01:33.590 --> 01:40.580
So I think what I'm going to do is right click on ability system components and close the other tabs

01:40.580 --> 01:51.470
for now and open my public folder ability system and get my aura ability system component H And look

01:51.470 --> 01:51.770
at that.

01:51.770 --> 01:53.420
So far it's clean.

01:53.420 --> 02:00.290
So we're going to add our first function to it and I'd like to make this function protected.

02:00.560 --> 02:07.890
So I'll make a protected section and the function is going to be void and it's going to be, let's just

02:07.890 --> 02:09.990
call it effect applied.

02:10.530 --> 02:13.110
And we know that it needs to have this signature.

02:13.110 --> 02:18.120
If we go back to ability system component, it needs to have these three inputs.

02:18.120 --> 02:20.940
So I'm going to copy them and I'll paste them here.

02:20.940 --> 02:28.710
Now funny thing is, those parameter names are actually optional here too, so bet you didn't know that.

02:28.710 --> 02:32.730
But I prefer to give them names here so they're descriptive.

02:32.730 --> 02:34.770
So I'm at least going to give them a name.

02:34.770 --> 02:38.040
I'll call it ability system component for that one.

02:38.040 --> 02:45.780
For the gameplay effect spec we'll call it effect spec for the active gameplay effect handle, we'll

02:45.780 --> 02:52.320
call this active effect handle and we can generate a definition.

02:52.320 --> 02:59.790
So now we have a callback, but we want to bind this to that delegate back in ability system component.

02:59.820 --> 03:01.860
We want to bind it to this one.

03:01.950 --> 03:03.420
The delegate of this type.

03:03.420 --> 03:10.350
I'm going to copy it, control F to find it and here it is on gameplay effect Applied Delegate to self.

03:10.350 --> 03:11.610
I want to bind to this.

03:11.610 --> 03:13.350
Where can I bind to it?

03:13.380 --> 03:21.750
Well, we typically like to do this when the actual game starts and not really in constructors as those

03:21.750 --> 03:24.510
are fired off quite early.

03:24.750 --> 03:34.200
So it'd be nice if we had some sort of spot to bind to this delegate early on and really a pretty easy

03:34.200 --> 03:42.420
way would be to make a function that we can call as soon as something happens like we've initialized

03:42.420 --> 03:45.060
our ability actor info, for example.

03:45.360 --> 03:47.070
That's pretty early on.

03:47.190 --> 03:54.300
So we could call some function to let the ability system know, okay, it's time to go ahead and bind

03:54.300 --> 03:55.530
to your delegates.

03:55.800 --> 04:00.870
And we know that we have a function here in Aura character.

04:00.870 --> 04:03.660
We call it an ability actor info.

04:03.960 --> 04:10.680
We're calling that an aura character when we want to call init the ability actor info on the ability

04:10.680 --> 04:11.910
system itself.

04:12.000 --> 04:20.040
Well, we could make this a virtual function on aura character base and just implement it in both aura

04:20.040 --> 04:22.050
character and aura enemy.

04:22.050 --> 04:28.560
And then whenever they call it, they can also call some function on the ability system to let it know

04:28.560 --> 04:32.970
it's time to bind to any delegates it wants to bind to.

04:33.180 --> 04:37.020
So I'm going to take this function init ability actor info.

04:37.050 --> 04:44.790
I'm going to declare it in aura character base and make it virtual and it can be protected.

04:44.790 --> 04:57.000
So I'm going to make a virtual void init ability actor info and I can just give it a empty definition

04:57.000 --> 04:57.810
here.

04:57.960 --> 05:02.970
But then in Aura character, we're now going to be overriding it.

05:02.970 --> 05:06.570
So it's a virtual override and.

05:06.870 --> 05:10.110
In aura an innate ability Actor Info.

05:10.170 --> 05:11.970
I'm going to open the CPP file.

05:11.970 --> 05:16.260
We can call some function on the ability system component here.

05:16.260 --> 05:18.990
Tell it to go ahead and start binding its delegates.

05:18.990 --> 05:20.490
So we'll get to that in a second.

05:20.490 --> 05:27.120
I'll keep that open, but I also want to override this in Aura enemy so Aura Enemy can do it as well.

05:27.120 --> 05:35.610
So in the protected section I'm going to say virtual void init ability actor info override and I'll

05:35.610 --> 05:37.080
generate the definition here.

05:37.080 --> 05:39.420
I don't care about the super call.

05:39.570 --> 05:45.450
So now Aura enemy and aura character can implement this each in their own ways.

05:45.480 --> 05:52.470
Now Aura enemy is just calling init ability actor info and it's beginplay right here.

05:52.500 --> 05:58.980
So now instead of calling it on the ability system component directly, I'm going to cut that line and

05:58.980 --> 06:05.670
put it right here in init ability actor info and then just call this function here in beginplay instead.

06:05.820 --> 06:11.980
But now we can do other things like call some function on the ability system component which we still

06:11.980 --> 06:12.850
haven't made.

06:12.850 --> 06:14.290
So why don't we make one?

06:14.560 --> 06:19.540
So aura ability system component here can get a public function.

06:19.540 --> 06:22.990
So let's give it a public section and it'll be a void function.

06:22.990 --> 06:29.620
And let's just say ability actor info set.

06:29.890 --> 06:36.280
So when this function is called, we know that the ability actor info has been set, so let's create

06:36.280 --> 06:37.750
a definition for it.

06:37.750 --> 06:41.680
And there we can call this when we set the ability actor info.

06:41.680 --> 06:49.180
So we'll do that in aura character in init ability actor info as soon as we call init ability actor

06:49.180 --> 06:50.530
info which is right here.

06:50.560 --> 06:56.110
Now we're getting the ability system component from aura player state, but we are going to need to

06:56.140 --> 06:57.340
cast it now.

06:57.490 --> 07:04.210
So we're going to say cast to you aura ability, system component.

07:04.870 --> 07:13.240
And by the way, writer is going to give me the aura ability system component header file now and we'll

07:13.240 --> 07:21.040
cast the aura player state get ability system component that's going to give us the ability system component

07:21.040 --> 07:26.950
we're casting now and we know that Aura character should have an aura ability system component.

07:26.950 --> 07:32.560
So we're going to take the result of this cast and call ability actor info set.

07:32.710 --> 07:38.170
Since we've set that cool, now we can do this on the enemy as well.

07:38.170 --> 07:46.690
So we have the ability system components we're going to cast to you aura, ability, system component,

07:48.760 --> 07:54.430
we're casting ability system component and then we're going to call ability actor info set.

07:54.580 --> 08:00.490
Now keep in mind that means the character is now dependent on the ability system component.

08:00.490 --> 08:06.130
And so we'll make sure that our ability system component doesn't have to know about the character.

08:06.130 --> 08:08.860
We'll keep the dependency one way in that sense.

08:09.370 --> 08:16.210
Okay, so now our aura enemy and aura character, as soon as they set their ability actor info, they'll

08:16.210 --> 08:23.980
call ability actor info set, which means the ability system component can now do things like bind to

08:23.980 --> 08:24.820
delegates.

08:24.820 --> 08:26.350
And that's what I'd like to do.

08:26.350 --> 08:29.590
So I'm going to go ahead and close Aura character.

08:29.590 --> 08:30.640
I'm done with it.

08:30.640 --> 08:38.320
I'm closing Aura Enemy or a character base and we're going to go into aura ability system component

08:38.320 --> 08:40.660
and we're going to bind our delegate.

08:41.380 --> 08:43.720
So let's recall what that delegate is called.

08:43.720 --> 08:48.460
It's this one on gameplay effect Applied delegate to Self.

08:48.580 --> 08:56.260
Let's go ahead and paste that into our ability actor info set and we're going to hit the dot and we're

08:56.260 --> 08:58.540
going to bind to this delegate.

08:58.750 --> 09:00.880
Now, what kind of delegate is it?

09:01.300 --> 09:05.590
We can go ahead and go to its declaration.

09:05.590 --> 09:08.740
It's a multicast delegate three params.

09:08.740 --> 09:12.160
It's not dynamic, so we can't use Add dynamic.

09:12.160 --> 09:18.220
We have to use add you object or any of the others.

09:18.220 --> 09:18.970
Right?

09:18.970 --> 09:25.030
But we're going to add you object, which means we're going to pass in this for the user object and

09:25.030 --> 09:28.480
for the function we'll pass in this function here.

09:28.510 --> 09:34.750
Don't forget the address of operator and don't forget to make sure it's fully qualified with the class

09:34.750 --> 09:35.320
name.

09:35.320 --> 09:43.180
Now we're binding this right, which means we have effect applied a callback that will be called in

09:43.180 --> 09:49.810
response to really any effect that gets applied to this ability system component.

09:50.200 --> 09:56.050
So why don't we just test this out by, say, printing a debug message.

09:56.050 --> 10:05.950
So we'll say G engine add on screen debug message, which takes a key we'll use one time.

10:06.170 --> 10:12.170
To display, let's say, eight point F, so eight seconds F color.

10:12.170 --> 10:14.420
Let's make it blue for the string.

10:14.420 --> 10:26.000
We'll make an F string that says effect applied and the rest of the inputs are optional.

10:26.000 --> 10:27.560
So that's all I want to do.

10:27.920 --> 10:31.250
And now I really, really want to test this out.

10:31.250 --> 10:34.550
So I'm going to run, but I'm going to run in debug mode.

10:34.580 --> 10:40.640
That way we could place a breakpoint there and see what the values are for all these input parameters

10:40.640 --> 10:41.600
passed in.

10:41.600 --> 10:45.710
But first let's get that debug message printed to the screen.

10:46.040 --> 10:53.630
Okay, so we're going to hit play and we're going to pick up a health crystal and there's our effect

10:53.630 --> 10:56.810
applied and we can pick up multiple.

10:56.810 --> 11:05.330
Now I probably should have not used key one because now all messages will replace older messages, but

11:05.330 --> 11:06.360
that's okay.

11:06.360 --> 11:12.630
Let's pick up a instant effect or rather a pickup that applies an instant effect.

11:12.660 --> 11:15.210
We see that we still get effect applied.

11:16.950 --> 11:17.910
Excellent.

11:18.030 --> 11:24.270
Now we're not really formatting a string that has any sort of information in it about the effect.

11:24.660 --> 11:26.790
I'm not going to bother with that.

11:26.790 --> 11:33.360
I'm going to instead place a breakpoint here and that way we can inspect these variables to our heart's

11:33.360 --> 11:33.980
content.

11:33.990 --> 11:37.680
So now I'm going to press play and let's pick up a health crystal.

11:38.460 --> 11:40.020
And we hit that break point.

11:40.050 --> 11:42.900
Now, here at the break point.

11:42.930 --> 11:45.510
Let's let Ryder collect some data.

11:45.630 --> 11:48.370
And here we have our data.

11:48.390 --> 11:54.870
So our callback has the ability system component, and that's owned by BP or a player state.

11:54.870 --> 11:56.010
That's great.

11:56.040 --> 11:59.490
We also have the effect spec which is down here.

11:59.490 --> 12:04.200
We can expand the dropdown and the effect spec has all kinds of information.

12:04.200 --> 12:10.090
We know that it's GE crystal heal, we know basically anything we want to know about it, right?

12:10.110 --> 12:14.130
We have all that information and of course active effect handle.

12:14.160 --> 12:20.340
This is the active effect handle we have that if we want it for whatever reason.

12:20.340 --> 12:21.120
Right?

12:21.390 --> 12:28.170
Remember, we used this before to remove an effect in the past with our health crystal.

12:28.500 --> 12:31.350
So this is really, really nice.

12:31.350 --> 12:37.130
We have the ability to get information at runtime about an effect being applied.

12:37.140 --> 12:42.340
So this is super useful for us and we'll be taking advantage of it in this course.

12:42.340 --> 12:45.670
So great job and I'll see you in the next video.
