Welcome back.
Now we know that we're successfully highlighting our enemy by getting the hit result under the mouse
cursor, but we'd actually like to do something more interesting than just showing a debug sphere that's
really only good for debug purposes.
So in this video we're going to use a post-process effect to highlight our enemy with an outline.
Now we mentioned that we would like to have our enemies derive from a common blueprint.
That way, if we need blueprint logic that they can all share, we can place that in an enemy base class
blueprint.
So just like we have an enemy which sort of serves as a base animation blueprint, we can make a base
enemy blueprint class.
So I'm going to make a new blueprint class here based on enemy.
And I'm going to call this BP underscore enemy base.
And all I'm going to do is go into our Goblin Slingshot blueprint.
Open class settings and set the parent class to be enemy base.
And I'll do the same thing for my Goblin spear.
I'll open class settings, set that parent to be enemy base.
And then if we do anything in the blueprint for enemy base, then all the other enemy blueprints will
inherit that functionality.
Now for our effect.
For an effect like an outline, we're going to need a post-process volume as it will be a post-process
effect.
Now I don't have one in my level, so I'm going to click the dropdown up here with the little cube,
go down to volumes and find Post-process volume and drag one in.
Now I want this to affect the whole level.
So in the details panel, I'm going to search for infinite and check infinite extent unbound.
And now if we add any post-process materials, they'll affect this entire level.
So with our post-process volume selected, I'm going to search for material and to our post-process
materials, we're going to add one.
Now this asset pack has a highlight material asset if we go to assets and materials, here's a highlight
Standing for Post-process highlight.
If we open that, it's this material.
For those of you who have taken my ultimate shooter course, we actually learned how to make this material
in that course if you're interested.
But all you have to know is that for this particular material, we've associated the value 250 with
the color red, and we're using something called custom depth stencil.
With this material and any objects in the world, any meshes can set their custom depth stencil value.
And if they set it to 250, we'll get this highlight effect on them.
Now, this only works if we configure our project to use the custom depth stencil pass.
So that means we have to go into edit and project settings and search for custom depth.
And here we see custom depth stencil pass and it says enabled.
But you have to change this to enabled with stencil.
Now this is very important.
Make sure you don't skip this part.
If you find that your highlight material is not working.
Come back into project settings and make sure custom depth stencil pass is enabled with stencil.
Again, don't forget enabled with stencil.
Not just enabled.
Okay.
We've beat that dead horse, so let's go ahead and close project settings and we'll add highlight to
our Post-process materials array for our Post-process volume.
So I'm going to click plus open the dropdown and select asset reference and open this dropdown and find
highlight.
And now our Post-process volume is using highlight, and that means any meshes that set their custom
depth stencil value to 250 will be highlighted.
Let's see how that looks by just selecting one of the goblins here in the world and here in its Details
panel, Let's select its mesh and search for custom depth.
And notice we have something that says Render custom depth pass.
If we check that, if we enable this Boolean, we can now set custom depth stencil value to a value.
And if we choose to 50, look at that.
Our goblin is now highlighted.
Now we won't go into too much depth on how highlight works, but if you go all the way to the beginning
here, there's this 1.6.
This is scaling the size of the outline.
If you choose a larger number such as two and apply the material, we'll get a thicker line.
In fact, let's put it at something like seven.
Now we can really see how thick it is.
So that's something to keep in mind.
I'm going to leave it at 1.6, just showing you that in case you wanted to tweak it.
But I'm pretty happy with 1.6.
Okay.
So now we know to highlight an enemy, all we have to do is set this variable, render custom depth
pass to true and change the custom depth stencil value to 250 and that's it.
And to hide that highlight, all we have to do is set this boolean back to false and it'll go away.
So that's all we need to do in our highlight and unhighlight functions.
So let's go ahead and close.
We'll save all.
And in highlight actor and Unhighlight actor, we can handle this.
So here's your quest.
You're going to handle this custom depth business on the mesh and our interface highlight and unhighlight
functions.
Now here's what the syntax looks like for setting that boolean, for rendering custom depth, and here's
how you set the custom depth stencil value.
So handle that.
But I also would like you to handle the weapon as well.
So figure out how to do that.
Pause the video and conquer this quest now.
Okay, so we don't really need this boolean variable anymore.
I'm going to go ahead and remove that.
All we need to do here is highlight and unhighlight.
We're going to do it right here in C plus plus.
Now to highlight the actor, we want to get the mesh and call set, render custom depth.
And when we're highlighting, we're going to pass in true and when we're un highlighting, we're going
to pass in false.
This is the same as checking and unchecking that checkbox that we checked on the mesh, but we also
want to set the value.
So we want to call, get mesh, set, custom depth, stencil value.
And remember it was 250 and we don't really like hard coding numbers like this.
So I'd like to just create a constant.
We'll go into perhaps ora dot h where we can define this constant or we could make it a macro symbol
either one for now, since we don't have a better place for it just yet.
We'll put this constant here and I'm just going to define it as custom depth red, and I'll define it
as 250 and we'll leave it as an integer literal actually, because if we go back, set custom depth
stencil value takes an int 32, so we'll pass in custom depth red.
And thanks to Ryder, I have Aura just popping up there for me and I don't have to worry about setting
that custom depth stencil value in Unhighlight.
In fact, once we set it, we don't have to set it again.
Setting it every single time is redundant, but that's a cheap operation, so that's fine.
But we do want to handle the weapon.
Now we know the weapon is created in Aura character base.
It should be a valid pointer and we don't expect highlight actor to be called before that pointer is
valid.
So we can simply access weapon set render custom depth.
We'll pass in true.
And we'll also say weapon set custom depth stencil value to custom depth red and for Unhighlight actor.
We'll simply call, set, render custom depth with false.
So let's try this out.
I'm going to run in debug mode.
No need to open up our asset editors.
All I want to do is play test.
So I'm going to press play, walk up to the enemies.
And it's working for these two, but not for this one.
Let's see why.
Now I remember that we set some collision presets on the Goblin Spear.
Right?
I'm going to browse to that Goblin Spear.
I'm actually going to edit Goblin Spear.
We'll open it directly and notice if we select our mesh.
We can scroll down, we'll see that we set its collision presets to custom here and we did that so we
can have it block the visibility channel.
Now, we did that to BP Goblin Sphere.
We didn't do it to the Slingshot enemy.
If we want to do that for all enemies, we should do it on the base class, whether that's the base
cplusplus class or the base blueprint class, I'd like to set it in the C plus plus class and then double
check to make sure that it's correct in Blueprint.
And if I come back to Collision Presets and hit the Arrow, it'll go back to its default and then the
blueprint will not be overwriting whatever we set in C plus plus.
So I'm going to close the editor.
We'll save all and we'll have a constructor for Aura Enemy.
Let's go ahead and make that constructor.
And here in Ora Enemy, we're going to set the collision response for the mesh.
So we're going to say get mesh.
And I'd like to say set collision.
Response to channel.
We'll use SEC visibility and this will be our block.
And that should result in the collision presets being changed automatically to custom.
Let's run this in debug mode.
And I'm going to go ahead and right click on one of these enemies.
I'm going to browse to the asset and come out and find BP enemy base.
I'm going to find its mesh.
And take a look at its collision presets.
We see that presets is set to custom and response to visibility is block.
So now we can press play, we can highlight and we see that.
Well, the slingshot is working.
Let's go back to Spear.
We always need to make sure that the blueprint doesn't override the cplusplus here, as we can see here,
that it actually is.
So we're going to set this from ignore to block on Goblin Spear there.
And now we're highlighting and it looks great.
That is nice.
Okay, now I'm just going to turn these enemies around so they're not facing the other way.
That way we can check to make sure that things are highlighting as they should.
And I'm going to take Aura's spring arm component and bring it in just a bit, just for now, so we
can see those enemies highlighting up close.
A little bit better.
And we can see that their weapons are highlighting and un highlighting and it looks great.
And we can highlight from one straight to another and things are working as they should.
Perfect.
So this is great.
Now we can see if we're hovering over a specific enemy so that later when we start implementing our
abilities, we'll know that we can target specific enemies.
And the red line indicates which one is currently targeted.
Perfect.
Excellent job.
I'll see you in the next video.