WEBVTT

00:06.860 --> 00:07.870
Welcome back.

00:07.880 --> 00:15.170
In this video, we're going to take a closer look at clamping and get a bit of a deeper understanding

00:15.170 --> 00:17.210
about how it works in gas.

00:17.240 --> 00:22.790
Now, we've clamped the changes to our health and our mana.

00:22.790 --> 00:32.090
And if we go back to our attributes set to our pre attribute change function, we see that we're getting

00:32.090 --> 00:35.660
the new value and we're clamping the new value.

00:35.660 --> 00:38.530
So where does this new value come from?

00:38.540 --> 00:47.810
Well, it comes from the calculation performed by our modifier in a gameplay effect when a given attribute

00:47.810 --> 00:48.380
changes.

00:48.380 --> 00:55.520
Now, of course, this function is called even when attributes are set directly, but if this is from

00:55.520 --> 01:02.390
a gameplay effect, that modifier returns the result of a calculation and this is receiving that.

01:02.390 --> 01:08.160
And of course we're checking its value, we're clamping it and making sure it doesn't go below zero

01:08.160 --> 01:09.750
or above the max value.

01:09.750 --> 01:10.320
Right?

01:10.860 --> 01:14.220
But let's see how this works with a little bit of testing.

01:14.220 --> 01:20.940
And you may have discovered this problem that we're about to see by Playtesting on your own.

01:22.130 --> 01:23.450
So I'm going to show debug.

01:23.450 --> 01:23.660
Right.

01:23.660 --> 01:27.230
And we have 50 health and our max health is 100.

01:27.290 --> 01:33.650
Now if we step into the fire, we've now made our fire tag five every second.

01:33.680 --> 01:34.190
Okay.

01:34.190 --> 01:35.280
So far so good.

01:35.300 --> 01:38.450
But what if we go and.

01:39.190 --> 01:40.900
Increase our health here.

01:40.900 --> 01:42.640
We'll pick up a health crystal.

01:42.640 --> 01:44.500
It's going up to 61.

01:44.500 --> 01:46.780
And let's pick up another one.

01:46.780 --> 01:47.140
Okay.

01:47.140 --> 01:51.850
It's going up to its 100 and let's pick up another one.

01:51.850 --> 01:58.210
And even though we are clamping our health, we see that our health is not higher than 100.

01:58.420 --> 02:03.340
But I'm going to step into the fire and our health isn't changing.

02:03.340 --> 02:04.720
So what's going on here?

02:04.720 --> 02:06.520
Why is our health not changing?

02:07.330 --> 02:15.490
Well, I'm going to close the editor and come back here and take a look at post gameplay effect execute.

02:15.490 --> 02:23.230
And I'm going to check to see if the attribute that's being changed is our health attribute.

02:23.260 --> 02:29.380
We can check that by saying if and we can take data dot evaluated data.

02:29.380 --> 02:38.770
So we're getting it from our data here dot attribute that gives us a gameplay attribute and we can compare

02:38.770 --> 02:41.920
that with get health attribute.

02:42.430 --> 02:50.350
So if we make it into this if statement, we know that the attribute changed is the health attribute.

02:50.350 --> 02:58.270
So what I'd like to do here is I'd like to see what that value is here in post gameplay effect execute.

02:58.270 --> 03:03.160
So let's go ahead and just print it to the screen.

03:03.160 --> 03:11.270
We're going to say, Gee, engine add on screen debug message and we'll just give it the key of one

03:11.270 --> 03:21.860
time to display three point f seconds f color red and f string print f and we'll format a string that

03:21.860 --> 03:30.230
says health percent f followed by get health.

03:31.580 --> 03:37.400
Okay, so we're going to print a string that says health and the value of our health.

03:37.400 --> 03:39.140
Let's run this in debug mode.

03:39.140 --> 03:45.110
Debug mode is always more useful because we can place breakpoints and check the values of things.

03:45.110 --> 03:48.410
So we're going to run in debug and let's see what happens here.

03:49.410 --> 03:49.800
Okay.

03:49.800 --> 03:56.640
So I'm going to show debug ability system and now I'm noticing that there's red text up here and we

03:56.640 --> 04:00.510
chose red for our color for the debug message.

04:00.510 --> 04:06.060
So we're going to have to try to strain our eyes a little bit to see what it says.

04:06.060 --> 04:13.860
But we see health is 45 and right here health, same value basically is what the bottom line is.

04:13.890 --> 04:16.380
We're getting consistency, right?

04:16.380 --> 04:20.700
But let's see what happens when we do what we did before.

04:20.700 --> 04:28.280
Now, how did we discover that bug where we stopped taking damage from that fire area?

04:28.290 --> 04:30.030
How do we repro that issue?

04:30.030 --> 04:33.060
Well, remember, I picked up a couple health crystals.

04:33.060 --> 04:39.060
I let my health go all the way up to 100, and then I picked up more health crystals.

04:39.060 --> 04:39.660
Okay.

04:39.660 --> 04:42.090
And then I stepped in the fire.

04:43.350 --> 04:43.860
Okay.

04:43.860 --> 04:53.520
So we see in our message and on show debug, we're getting 100 and we're not going down.

04:53.520 --> 05:03.210
So it's the same value here both in post gameplay effect, execute and here in pre attribute change.

05:03.210 --> 05:06.510
So how come we stopped getting damage?

05:06.780 --> 05:12.180
Well, what I'd like to take a look at is the value here of new value before we clamp it.

05:12.360 --> 05:20.190
So I'm going to repro the bug by going and picking up a couple health crystals and then going way up

05:20.190 --> 05:25.080
past 100 or at least trying to and then going and stepping in the fire.

05:25.080 --> 05:30.720
And then I'm going to stick a breakpoint right here and we're going to hit that breakpoint because we're

05:30.720 --> 05:31.650
in the fire.

05:31.890 --> 05:33.900
Now let's hover over new value.

05:33.930 --> 05:40.320
We see that it's 160 and that is not what we expected, right?

05:40.320 --> 05:42.940
Because we should be clamping every time.

05:42.940 --> 05:44.650
So why is it 160?

05:45.140 --> 05:52.520
Well pre attribute change is getting new value from our modifier on the gameplay effect that's being

05:52.520 --> 05:53.360
applied.

05:53.480 --> 05:57.740
And then we're clamping it before the attribute changes.

05:58.280 --> 06:00.340
So that's great.

06:00.350 --> 06:05.770
But this clamp here is not going to permanently change that modifier.

06:05.780 --> 06:12.200
It just changes the value that is being returned from querying that modifier.

06:12.290 --> 06:17.870
And if we have some other gameplay effect that's going to have its own modifier queried, it's going

06:17.870 --> 06:20.720
to recalculate the value from current value.

06:20.720 --> 06:24.170
So it's kind of like the value was never actually clamped.

06:24.200 --> 06:29.600
We clamped it before the attribute changed, but that modifier recalculates.

06:29.600 --> 06:35.480
So if we continue this and then we hit our next breakpoint, we see that it's 155.

06:35.480 --> 06:39.140
So we are going down thanks to that fire area.

06:39.780 --> 06:42.930
But it shouldn't be 155 in the first place, should it?

06:43.140 --> 06:52.020
Now we can properly clamp this by clamping again over here and post game play effect execute because

06:52.020 --> 06:58.230
this happens after the gameplay effect has already been applied, we can clamp that value again and

06:58.230 --> 07:04.470
we don't have to worry that since we're changing it again, maybe it's going to replicate again down

07:04.470 --> 07:05.490
to clients.

07:05.580 --> 07:11.820
No, we can change it here and there will only be a single replication resulting from changing the attributes

07:11.850 --> 07:12.570
value.

07:12.930 --> 07:16.710
So I'm going to remove that breakpoint and continue.

07:17.960 --> 07:23.840
And we'll close out of the editor and here in post gameplay effect execute.

07:23.840 --> 07:36.170
If health is the value being changed, then we're going to say set health equal to F math clamp, get

07:36.200 --> 07:41.930
health, we're going to clamp between zero and get max health.

07:43.670 --> 07:47.930
So let's run and debug mode and see what happens now.

07:48.600 --> 07:54.780
So let's press play and we'll pick up a couple health crystals, go up to 100 health.

07:54.810 --> 07:58.890
We'll pick up another health crystal and go way beyond that.

07:58.890 --> 08:02.340
And we'll go step in the fire and look at that.

08:02.370 --> 08:06.810
We see that our health is going down to the correct values.

08:06.810 --> 08:07.080
Why?

08:07.110 --> 08:13.400
Because we're clamping in post gameplay effect execute and we're actually setting our health.

08:13.410 --> 08:19.110
We're not just changing new value, which is what we were doing up here in pre attribute change.

08:19.110 --> 08:23.370
This just changes the value returned from querying the modifier.

08:23.370 --> 08:28.140
But here in post gameplay effect execute we're actually setting the health.

08:28.140 --> 08:33.120
So this is a legit set of the health attribute.

08:33.330 --> 08:37.110
So yes, we can clamp here in pre attribute change.

08:37.320 --> 08:40.020
That's basically all that this function is good for.

08:40.020 --> 08:47.430
But remember that all this does is clamp what's returned from querying the modifier.

08:47.430 --> 08:54.340
Anything else that queries the modifier again is going to recalculate what's returned from the modifier

08:54.340 --> 08:55.450
of any given effect.

08:55.480 --> 09:03.220
We are going to actually set the value to a clamped value here in post gameplay effect execute.

09:03.220 --> 09:08.440
And when all is said and done, the actual value will be set here.

09:08.560 --> 09:12.370
Okay, so I can go ahead and remove this onscreen debug message.

09:12.370 --> 09:19.210
And now that we understand clamping a little better, let's go ahead and clamp our mana here as well.

09:19.210 --> 09:28.030
So if the attribute is get mana attribute, then we're going to go ahead and clamp it between the value

09:28.030 --> 09:30.880
of get mana and get max Mana.

09:31.810 --> 09:38.650
And of course we're not calling set health, we're calling set mana and now we're clamping mana as well.

09:38.650 --> 09:39.730
So great job.

09:39.730 --> 09:41.380
I'll see you in the next video.
