WEBVTT

00:07.090 --> 00:08.200
Welcome back.

00:08.200 --> 00:15.100
So now that we have four new attributes in our attribute set, we're going to learn how to easily create

00:15.100 --> 00:22.450
some accessor functions to retrieve and set these, even though usually we don't set these from code

00:22.450 --> 00:28.030
directly, we use gameplay effects, but we haven't learned about gameplay effects just yet, so we

00:28.030 --> 00:33.430
do need to know that we can in fact set these from code with regular old setters.

00:33.460 --> 00:42.460
Now for getters and setters, there exist some pretty handy macros that make it easy to mutate and access

00:42.460 --> 00:44.080
these attributes.

00:44.080 --> 00:47.500
And I'm just going to show you one for health.

00:47.500 --> 00:53.350
Just under health, I'm going to use the gas specific macro gameplay attribute.

00:54.070 --> 00:57.160
Underscore property getter.

00:57.250 --> 01:00.430
Now, this requires two inputs.

01:00.430 --> 01:07.810
The class name, which is you, or a attribute set, of course, and the property name, which is health.

01:07.990 --> 01:11.590
So what exactly happens when we call this?

01:11.590 --> 01:14.440
Well, let's go ahead and just jump to its definition.

01:14.440 --> 01:16.480
I'm going to right click here in writer.

01:16.480 --> 01:19.600
It's go to declaration or usages.

01:19.600 --> 01:23.770
You can just peek the definition in Visual Studio, but here it is.

01:23.770 --> 01:25.960
Gameplay attribute Property getter.

01:25.960 --> 01:27.400
It's a macro.

01:27.400 --> 01:28.540
It's defined right here.

01:28.540 --> 01:33.460
In fact, here in attribute set this big comment explains it.

01:33.490 --> 01:39.790
It says This defines a set of helper functions for accessing and initializing attributes to avoid having

01:39.790 --> 01:41.620
to manually write these functions.

01:41.620 --> 01:46.300
It would create the following functions for attribute health.

01:46.300 --> 01:49.420
It uses health as the example.

01:49.420 --> 01:57.770
It says that these macros result in creating Get Health, which is a const getter, set health which

01:57.770 --> 02:04.250
does what you'd think a set health function would do, and in it health which initializes the health,

02:04.280 --> 02:10.010
it says to use this in your game you can define something like this and then add game specific functions

02:10.010 --> 02:11.120
as necessary.

02:11.120 --> 02:15.620
And it says here, define this macro called attribute accessors.

02:15.620 --> 02:23.960
If you define this, then when you call attribute accessors, it will call these four macros which create

02:23.960 --> 02:31.010
the getter for the attribute, the getter for the value, the setter for the attribute and the emitter

02:31.010 --> 02:32.330
for the attribute.

02:32.330 --> 02:36.530
And why do we have get health attribute and get health?

02:36.530 --> 02:43.850
Well, that's because the attribute itself is its own type of gameplay attribute.

02:43.850 --> 02:51.470
That's the attribute that gameplay attribute data contains within and get health would return just the

02:51.470 --> 02:51.860
float.

02:51.860 --> 02:53.870
You could see it returns float here.

02:53.870 --> 03:01.100
So one returns the actual attribute object, the other returns the numerical value of health.

03:01.130 --> 03:02.480
See the difference?

03:02.480 --> 03:04.910
So we can take a look at these macros.

03:04.910 --> 03:08.570
It's not imperative that we understand the macros.

03:08.570 --> 03:10.760
This is macro creation magic.

03:10.790 --> 03:18.050
This macro here is generating a new function called get property attribute.

03:18.140 --> 03:23.810
So it's using macro magic to generate a getter function for us.

03:23.840 --> 03:30.830
And I'd just like to point out one quick difference between set and init.

03:30.860 --> 03:36.170
You see, set is going to set the numeric attribute base.

03:36.170 --> 03:43.010
That's the base value for the attribute, whereas init sets the base value but also sets the current

03:43.010 --> 03:45.170
value base and current.

03:45.200 --> 03:52.970
It's basically saying start off with the same base and current value, which is what we pass in.

03:52.970 --> 03:56.900
So we get these nice accessor functions.

03:56.900 --> 04:05.030
If we call these macros as we saw in aura attribute set dot h, I called gameplay attribute property

04:05.030 --> 04:05.360
getter.

04:05.360 --> 04:12.950
This is going to generate the getter for the health attribute, not its numerical value, but an object

04:12.950 --> 04:18.680
of type gameplay attribute which is contained within that attribute data.

04:18.920 --> 04:25.970
So why don't we go ahead and follow what the attribute set header recommends and that is to create this

04:26.000 --> 04:28.160
attribute Accessors macro.

04:28.160 --> 04:31.580
Let's go ahead and copy these lines.

04:32.030 --> 04:37.490
And back in our aura attributes set at the top underneath all the includes.

04:37.490 --> 04:38.810
We'll go ahead and paste them.

04:38.810 --> 04:41.840
We need to delete these stars.

04:41.840 --> 04:45.860
The asterisks that came from that multi-line comment.

04:46.010 --> 04:50.360
And now we have this attribute accessors macro.

04:50.360 --> 04:55.190
And if we call this, then we don't have to use all four of these.

04:55.190 --> 05:00.710
So just under health, I'm going to replace this with attribute accessors here.

05:00.830 --> 05:05.300
Now hovering over it says ability system component is incomplete.

05:05.330 --> 05:08.900
That means we're going to have to include it here in the header file.

05:08.900 --> 05:11.540
There's no way to get around that.

05:11.540 --> 05:18.710
So I'm going to go into aura attribute set dot CPP up at the top where I've included ability system

05:18.710 --> 05:19.310
component.

05:19.310 --> 05:25.520
I'm just going to go ahead and control X to cut that out and we're going to include it right here in

05:25.520 --> 05:26.660
the attribute set.

05:26.690 --> 05:30.710
That way we can use these macros.

05:30.830 --> 05:36.750
So the attribute accessors thing is just another one of those boilerplate things that you're going to

05:36.750 --> 05:38.220
add to your attributes.

05:38.220 --> 05:42.750
And because of this, we can now use those accessor functions.

05:42.750 --> 05:51.060
For example, if I want to initialize health to say a value of 100, I can go into my constructor and

05:51.060 --> 05:54.270
use init health and pass in 100.

05:54.540 --> 06:02.220
And even though I didn't create an init health function, I used my attribute accessors macro which

06:02.220 --> 06:08.940
calls these four macros, one of which creates the emitter and by default that's called init health.

06:09.000 --> 06:11.850
So I can use that to init the health.

06:11.850 --> 06:13.770
But how do we see that change?

06:13.770 --> 06:16.110
How can we verify that it's working?

06:16.140 --> 06:18.450
Well, we can compile and launch the editor.

06:18.450 --> 06:21.180
I'm just going to go ahead and run and debug mode.

06:21.680 --> 06:24.780
And right here in the editor, I can press play.

06:24.800 --> 06:30.410
I can click in the viewport and I'm going to hit the tilde key to bring up the console and I'm going

06:30.410 --> 06:34.580
to type the console command show debug.

06:34.580 --> 06:37.340
That's one word ability system.

06:37.340 --> 06:38.750
That's also one word.

06:38.750 --> 06:42.530
So two words total show debug ability system.

06:42.740 --> 06:49.250
Now this brings up a debug view for the ability system and it has a lot of information.

06:49.250 --> 06:53.870
It shows attributes for Avatar or a character.

06:53.900 --> 06:59.780
See, So we know that our avatar actor has been set correctly to be or a character.

06:59.870 --> 07:01.130
It says authority.

07:01.130 --> 07:03.560
That means we're looking at the authority version.

07:03.560 --> 07:10.460
Now there are no other client machines, so the only version there is is the authority version.

07:10.460 --> 07:14.270
And we see for owner BP or a player state.

07:14.270 --> 07:21.300
So it knows that our avatar actor is the character and our owner actor is the player state.

07:21.300 --> 07:29.160
That's all thanks to calling init ability actor info we see in red showing debug for BP or a character

07:29.160 --> 07:33.330
press page up and page down to cycle between targets.

07:33.330 --> 07:41.010
So if we press page up we can cycle to other targets and we see the name change right here.

07:41.010 --> 07:48.780
It says showing debug for BP Goblin Slingshot C1 But we can cycle back around to our character.

07:48.780 --> 07:50.940
It shows some other information.

07:50.940 --> 07:58.410
It shows the name of the computer, that's my computer's name, and it actually has the location and

07:58.410 --> 08:02.940
rotation right here and you can see it update as I'm moving around.

08:02.940 --> 08:07.980
We have an instigator and an owner for our ability system component.

08:08.010 --> 08:13.860
We see the controller is BP or a player controller and the pawn is BP or a character.

08:13.860 --> 08:16.350
So it knows a lot of this information.

08:16.350 --> 08:19.830
And beneath all that we see owned tags.

08:19.830 --> 08:22.920
We're going to look at that as soon as we get into gameplay tags.

08:22.920 --> 08:26.910
And yet underneath all of that, we see the four attributes.

08:26.910 --> 08:29.940
Here we have health followed by 100.

08:29.940 --> 08:31.860
That's what we initialized it to.

08:31.860 --> 08:37.920
And then Max Health Mana and Max Mana, the other attributes and we didn't initialize those.

08:37.920 --> 08:46.590
So show debug ability system is a great way to sort of debug some of our attribute values and also see

08:46.620 --> 08:48.960
what gameplay tags our character has.

08:49.110 --> 08:51.960
So that's a nice way that we can do some debug.

08:51.960 --> 08:57.270
I'm going to go ahead and close out of the editor and now we've added some boilerplate here that we

08:57.270 --> 09:05.280
can reuse for all of our attributes by using the attribute accessors and that gives us these functions

09:05.280 --> 09:07.620
we can use to initialize and set.

09:07.650 --> 09:09.780
Now I'll give you a bit of a spoiler.

09:09.810 --> 09:14.100
The constructor is too early to call the setter.

09:14.100 --> 09:16.470
That's why we have the emitter here.

09:16.470 --> 09:21.990
But now we have this attribute accessors which we could use with all of our attributes.

09:22.140 --> 09:25.500
So here's what your quest will be for this video.

09:25.620 --> 09:30.800
You're going to use that attribute accessors macro on the other attributes.

09:30.810 --> 09:33.360
So go ahead and add that.

09:33.360 --> 09:36.180
That way you'll have those accessor functions.

09:36.180 --> 09:40.890
And once you have those, you can now give initial values to all of the attributes.

09:40.890 --> 09:48.510
So do that in the constructor and then use show debug ability system by playtesting the game and then

09:48.510 --> 09:51.830
you can verify that those initial values have been set.

09:51.840 --> 09:56.130
So pause the video and conquer this quest now.

09:59.320 --> 10:03.100
Okay, so we can use our attribute accessors macro.

10:03.310 --> 10:07.150
I'm going to be nice and lazy and copy it.

10:07.180 --> 10:13.900
Being very careful to change it from health to max health for this one, I'll copy it again.

10:13.900 --> 10:18.760
And just under Mana we'll add that changing it to Manna.

10:18.760 --> 10:21.070
And finally we have Max Manna.

10:21.070 --> 10:23.440
We'll change it to Max Manna as well.

10:23.440 --> 10:25.840
So now we have attribute accessors.

10:25.840 --> 10:30.340
For the rest we can go back and call init for all of them.

10:30.340 --> 10:33.130
I'm going to call init max health.

10:33.520 --> 10:37.810
Give it a value of 100 we can call init manna.

10:37.840 --> 10:40.150
Doesn't matter what values we choose.

10:40.150 --> 10:46.450
I'll just go ahead and choose 50 for mana and we'll use init max manna.

10:46.780 --> 10:51.610
I'll go ahead and give it 50 as well and we can go ahead and run.

10:51.610 --> 10:53.200
By the way, I'm running in debug mode.

10:53.200 --> 11:00.080
We're not really debugging per se, but don't you worry, we'll be debugging a lot in this course.

11:00.080 --> 11:02.210
We're just still kind of getting started here.

11:02.210 --> 11:06.320
But don't worry, we'll learn a lot about debugging throughout the course.

11:06.320 --> 11:12.680
Right now it's not that important whether you choose to run or debug at this point in time.

11:12.680 --> 11:14.750
All right, so we're going to hit play.

11:15.020 --> 11:16.370
I'm going to bring up the console.

11:16.370 --> 11:19.010
I'm just going to press up on the keyboard.

11:19.010 --> 11:26.330
That'll bring up my last command hitting enter and I see health and Max health are both 100 mana and

11:26.330 --> 11:28.220
Max Mana are both 50.

11:28.250 --> 11:33.080
They have been initialized successfully and it's looking good.

11:33.230 --> 11:33.860
Excellent.

11:33.860 --> 11:34.940
So great job.

11:34.940 --> 11:39.260
We now have those attribute accessors yet another piece of boilerplate.

11:39.260 --> 11:41.120
But now you know what it does.

11:41.120 --> 11:43.550
You don't need to be intimidated by it when you see it.

11:43.550 --> 11:47.660
You know that it simply creates some accessor functions that we can use.

11:47.690 --> 11:52.550
And I'll say it again, we typically don't use those functions to change attributes.

11:52.550 --> 11:58.040
We can, but we like to use gameplay effects instead as those can be predicted.

11:58.040 --> 12:00.620
And we'll learn about those when we get to gameplay effects.

12:00.620 --> 12:03.290
But for now we have accessors.

12:03.290 --> 12:05.540
So great job and I'll see you soon.
