WEBVTT

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

00:08.410 --> 00:14.230
Now we know that we're successfully highlighting our enemy by getting the hit result under the mouse

00:14.230 --> 00:19.810
cursor, but we'd actually like to do something more interesting than just showing a debug sphere that's

00:19.810 --> 00:22.060
really only good for debug purposes.

00:22.060 --> 00:29.030
So in this video we're going to use a post-process effect to highlight our enemy with an outline.

00:29.050 --> 00:34.990
Now we mentioned that we would like to have our enemies derive from a common blueprint.

00:35.020 --> 00:41.350
That way, if we need blueprint logic that they can all share, we can place that in an enemy base class

00:41.350 --> 00:42.410
blueprint.

00:42.430 --> 00:49.870
So just like we have an enemy which sort of serves as a base animation blueprint, we can make a base

00:49.870 --> 00:51.130
enemy blueprint class.

00:51.130 --> 00:55.000
So I'm going to make a new blueprint class here based on enemy.

00:56.800 --> 01:00.960
And I'm going to call this BP underscore enemy base.

01:00.970 --> 01:06.190
And all I'm going to do is go into our Goblin Slingshot blueprint.

01:07.380 --> 01:13.410
Open class settings and set the parent class to be enemy base.

01:14.920 --> 01:18.610
And I'll do the same thing for my Goblin spear.

01:18.850 --> 01:24.970
I'll open class settings, set that parent to be enemy base.

01:25.330 --> 01:32.920
And then if we do anything in the blueprint for enemy base, then all the other enemy blueprints will

01:32.920 --> 01:35.380
inherit that functionality.

01:35.410 --> 01:37.000
Now for our effect.

01:37.000 --> 01:43.540
For an effect like an outline, we're going to need a post-process volume as it will be a post-process

01:43.540 --> 01:44.260
effect.

01:44.290 --> 01:50.740
Now I don't have one in my level, so I'm going to click the dropdown up here with the little cube,

01:51.010 --> 01:56.560
go down to volumes and find Post-process volume and drag one in.

01:56.680 --> 01:58.840
Now I want this to affect the whole level.

01:58.840 --> 02:05.470
So in the details panel, I'm going to search for infinite and check infinite extent unbound.

02:05.470 --> 02:11.440
And now if we add any post-process materials, they'll affect this entire level.

02:11.530 --> 02:17.840
So with our post-process volume selected, I'm going to search for material and to our post-process

02:17.840 --> 02:19.710
materials, we're going to add one.

02:19.730 --> 02:28.910
Now this asset pack has a highlight material asset if we go to assets and materials, here's a highlight

02:28.910 --> 02:30.830
Standing for Post-process highlight.

02:30.830 --> 02:34.070
If we open that, it's this material.

02:34.070 --> 02:39.410
For those of you who have taken my ultimate shooter course, we actually learned how to make this material

02:39.410 --> 02:41.140
in that course if you're interested.

02:41.150 --> 02:47.960
But all you have to know is that for this particular material, we've associated the value 250 with

02:47.960 --> 02:52.910
the color red, and we're using something called custom depth stencil.

02:52.910 --> 03:01.130
With this material and any objects in the world, any meshes can set their custom depth stencil value.

03:01.130 --> 03:06.080
And if they set it to 250, we'll get this highlight effect on them.

03:06.080 --> 03:12.350
Now, this only works if we configure our project to use the custom depth stencil pass.

03:12.350 --> 03:17.830
So that means we have to go into edit and project settings and search for custom depth.

03:19.830 --> 03:24.140
And here we see custom depth stencil pass and it says enabled.

03:24.150 --> 03:27.430
But you have to change this to enabled with stencil.

03:27.450 --> 03:29.120
Now this is very important.

03:29.130 --> 03:31.710
Make sure you don't skip this part.

03:31.710 --> 03:36.030
If you find that your highlight material is not working.

03:36.060 --> 03:43.310
Come back into project settings and make sure custom depth stencil pass is enabled with stencil.

03:43.320 --> 03:47.550
Again, don't forget enabled with stencil.

03:47.550 --> 03:49.590
Not just enabled.

03:49.890 --> 03:50.400
Okay.

03:50.400 --> 03:57.030
We've beat that dead horse, so let's go ahead and close project settings and we'll add highlight to

03:57.030 --> 04:00.660
our Post-process materials array for our Post-process volume.

04:00.660 --> 04:08.400
So I'm going to click plus open the dropdown and select asset reference and open this dropdown and find

04:09.000 --> 04:10.010
highlight.

04:10.020 --> 04:17.310
And now our Post-process volume is using highlight, and that means any meshes that set their custom

04:17.310 --> 04:21.060
depth stencil value to 250 will be highlighted.

04:21.070 --> 04:26.350
Let's see how that looks by just selecting one of the goblins here in the world and here in its Details

04:26.350 --> 04:30.490
panel, Let's select its mesh and search for custom depth.

04:31.450 --> 04:35.830
And notice we have something that says Render custom depth pass.

04:35.860 --> 04:43.810
If we check that, if we enable this Boolean, we can now set custom depth stencil value to a value.

04:43.810 --> 04:47.830
And if we choose to 50, look at that.

04:48.010 --> 04:50.510
Our goblin is now highlighted.

04:50.560 --> 04:58.150
Now we won't go into too much depth on how highlight works, but if you go all the way to the beginning

04:58.150 --> 05:01.060
here, there's this 1.6.

05:01.060 --> 05:04.120
This is scaling the size of the outline.

05:04.120 --> 05:10.030
If you choose a larger number such as two and apply the material, we'll get a thicker line.

05:10.030 --> 05:12.880
In fact, let's put it at something like seven.

05:15.460 --> 05:18.060
Now we can really see how thick it is.

05:18.100 --> 05:19.760
So that's something to keep in mind.

05:19.780 --> 05:24.640
I'm going to leave it at 1.6, just showing you that in case you wanted to tweak it.

05:24.640 --> 05:26.830
But I'm pretty happy with 1.6.

05:26.860 --> 05:27.400
Okay.

05:27.400 --> 05:33.820
So now we know to highlight an enemy, all we have to do is set this variable, render custom depth

05:33.820 --> 05:40.540
pass to true and change the custom depth stencil value to 250 and that's it.

05:40.540 --> 05:47.380
And to hide that highlight, all we have to do is set this boolean back to false and it'll go away.

05:47.680 --> 05:52.000
So that's all we need to do in our highlight and unhighlight functions.

05:52.000 --> 05:53.830
So let's go ahead and close.

05:53.830 --> 05:55.120
We'll save all.

05:55.480 --> 05:59.950
And in highlight actor and Unhighlight actor, we can handle this.

05:59.980 --> 06:01.750
So here's your quest.

06:01.840 --> 06:09.070
You're going to handle this custom depth business on the mesh and our interface highlight and unhighlight

06:09.070 --> 06:10.050
functions.

06:10.060 --> 06:17.000
Now here's what the syntax looks like for setting that boolean, for rendering custom depth, and here's

06:17.000 --> 06:19.580
how you set the custom depth stencil value.

06:19.580 --> 06:21.050
So handle that.

06:21.050 --> 06:24.410
But I also would like you to handle the weapon as well.

06:24.410 --> 06:27.020
So figure out how to do that.

06:27.020 --> 06:30.740
Pause the video and conquer this quest now.

06:33.560 --> 06:38.270
Okay, so we don't really need this boolean variable anymore.

06:38.300 --> 06:40.940
I'm going to go ahead and remove that.

06:41.990 --> 06:46.730
All we need to do here is highlight and unhighlight.

06:46.730 --> 06:49.470
We're going to do it right here in C plus plus.

06:49.490 --> 06:58.460
Now to highlight the actor, we want to get the mesh and call set, render custom depth.

06:58.460 --> 07:06.140
And when we're highlighting, we're going to pass in true and when we're un highlighting, we're going

07:06.140 --> 07:07.460
to pass in false.

07:07.490 --> 07:14.840
This is the same as checking and unchecking that checkbox that we checked on the mesh, but we also

07:14.870 --> 07:16.640
want to set the value.

07:16.670 --> 07:23.030
So we want to call, get mesh, set, custom depth, stencil value.

07:23.030 --> 07:31.460
And remember it was 250 and we don't really like hard coding numbers like this.

07:31.460 --> 07:35.700
So I'd like to just create a constant.

07:35.730 --> 07:44.160
We'll go into perhaps ora dot h where we can define this constant or we could make it a macro symbol

07:44.280 --> 07:49.560
either one for now, since we don't have a better place for it just yet.

07:49.590 --> 07:58.590
We'll put this constant here and I'm just going to define it as custom depth red, and I'll define it

07:58.590 --> 08:06.840
as 250 and we'll leave it as an integer literal actually, because if we go back, set custom depth

08:06.840 --> 08:14.580
stencil value takes an int 32, so we'll pass in custom depth red.

08:15.820 --> 08:23.020
And thanks to Ryder, I have Aura just popping up there for me and I don't have to worry about setting

08:23.020 --> 08:26.200
that custom depth stencil value in Unhighlight.

08:26.200 --> 08:29.670
In fact, once we set it, we don't have to set it again.

08:29.680 --> 08:35.110
Setting it every single time is redundant, but that's a cheap operation, so that's fine.

08:35.110 --> 08:37.870
But we do want to handle the weapon.

08:37.870 --> 08:42.280
Now we know the weapon is created in Aura character base.

08:42.310 --> 08:50.140
It should be a valid pointer and we don't expect highlight actor to be called before that pointer is

08:50.140 --> 08:50.890
valid.

08:50.890 --> 08:55.630
So we can simply access weapon set render custom depth.

08:55.630 --> 08:57.340
We'll pass in true.

08:58.180 --> 09:10.480
And we'll also say weapon set custom depth stencil value to custom depth red and for Unhighlight actor.

09:11.100 --> 09:15.200
We'll simply call, set, render custom depth with false.

09:15.210 --> 09:16.730
So let's try this out.

09:16.740 --> 09:18.660
I'm going to run in debug mode.

09:19.350 --> 09:21.990
No need to open up our asset editors.

09:21.990 --> 09:23.910
All I want to do is play test.

09:23.910 --> 09:27.720
So I'm going to press play, walk up to the enemies.

09:31.020 --> 09:34.230
And it's working for these two, but not for this one.

09:34.230 --> 09:35.550
Let's see why.

09:35.580 --> 09:41.730
Now I remember that we set some collision presets on the Goblin Spear.

09:41.760 --> 09:42.060
Right?

09:42.060 --> 09:45.330
I'm going to browse to that Goblin Spear.

09:45.360 --> 09:47.910
I'm actually going to edit Goblin Spear.

09:47.910 --> 09:52.800
We'll open it directly and notice if we select our mesh.

09:53.640 --> 10:01.050
We can scroll down, we'll see that we set its collision presets to custom here and we did that so we

10:01.050 --> 10:03.900
can have it block the visibility channel.

10:03.900 --> 10:06.420
Now, we did that to BP Goblin Sphere.

10:06.420 --> 10:08.580
We didn't do it to the Slingshot enemy.

10:08.580 --> 10:14.100
If we want to do that for all enemies, we should do it on the base class, whether that's the base

10:14.100 --> 10:21.330
cplusplus class or the base blueprint class, I'd like to set it in the C plus plus class and then double

10:21.330 --> 10:24.060
check to make sure that it's correct in Blueprint.

10:24.060 --> 10:30.540
And if I come back to Collision Presets and hit the Arrow, it'll go back to its default and then the

10:30.540 --> 10:34.740
blueprint will not be overwriting whatever we set in C plus plus.

10:34.740 --> 10:36.480
So I'm going to close the editor.

10:36.480 --> 10:40.980
We'll save all and we'll have a constructor for Aura Enemy.

10:40.980 --> 10:43.710
Let's go ahead and make that constructor.

10:48.870 --> 10:54.200
And here in Ora Enemy, we're going to set the collision response for the mesh.

10:54.210 --> 10:55.980
So we're going to say get mesh.

10:56.370 --> 10:59.010
And I'd like to say set collision.

11:00.850 --> 11:03.010
Response to channel.

11:03.010 --> 11:10.030
We'll use SEC visibility and this will be our block.

11:11.930 --> 11:18.470
And that should result in the collision presets being changed automatically to custom.

11:18.500 --> 11:20.240
Let's run this in debug mode.

11:21.070 --> 11:24.310
And I'm going to go ahead and right click on one of these enemies.

11:24.310 --> 11:29.770
I'm going to browse to the asset and come out and find BP enemy base.

11:29.950 --> 11:32.290
I'm going to find its mesh.

11:33.050 --> 11:35.700
And take a look at its collision presets.

11:35.720 --> 11:42.080
We see that presets is set to custom and response to visibility is block.

11:42.110 --> 11:45.950
So now we can press play, we can highlight and we see that.

11:46.830 --> 11:49.320
Well, the slingshot is working.

11:51.250 --> 11:52.450
Let's go back to Spear.

11:52.450 --> 11:59.950
We always need to make sure that the blueprint doesn't override the cplusplus here, as we can see here,

11:59.950 --> 12:01.300
that it actually is.

12:01.300 --> 12:06.940
So we're going to set this from ignore to block on Goblin Spear there.

12:08.710 --> 12:12.370
And now we're highlighting and it looks great.

12:13.820 --> 12:15.890
That is nice.

12:16.730 --> 12:22.190
Okay, now I'm just going to turn these enemies around so they're not facing the other way.

12:24.940 --> 12:30.910
That way we can check to make sure that things are highlighting as they should.

12:31.470 --> 12:38.460
And I'm going to take Aura's spring arm component and bring it in just a bit, just for now, so we

12:38.460 --> 12:41.400
can see those enemies highlighting up close.

12:41.850 --> 12:42.900
A little bit better.

12:42.900 --> 12:49.110
And we can see that their weapons are highlighting and un highlighting and it looks great.

12:49.960 --> 12:55.270
And we can highlight from one straight to another and things are working as they should.

12:56.140 --> 12:56.860
Perfect.

12:56.860 --> 12:57.580
So this is great.

12:57.610 --> 13:04.210
Now we can see if we're hovering over a specific enemy so that later when we start implementing our

13:04.210 --> 13:08.800
abilities, we'll know that we can target specific enemies.

13:08.800 --> 13:13.870
And the red line indicates which one is currently targeted.

13:14.550 --> 13:15.630
Perfect.

13:15.840 --> 13:16.870
Excellent job.

13:16.890 --> 13:18.570
I'll see you in the next video.
