Welcome back.
Now we have death working.
And if we get our enemies down to zero health, we know that we can rag doll them.
Now, in this video, I'm concerned with a little bit extra of an effect.
I'd like to dissolve the enemy.
So what do I mean by dissolve?
Well, let me go ahead and close down any of those tabs I don't need.
And let's take a look in our assets folder into materials.
Notice I have something called M Dissolve Effect.
Let's take a look at this material.
Here's what it looks like now.
This has a number of material parameters and by number I mean two.
Let's open my dissolve effect and check it out.
We have dissolve and glow.
Now Glow is going to make those edges glow just a bit more or less, depending on the value.
But look at the dissolve parameter.
If I click and drag to the right, it dissolves away.
If I drag to the left, then the material comes back.
Now if we look in m dissolve effect, we see that it's just a base color and that's this pink color.
That's why it looks pink like this.
But then we also have this little bit here.
This is what's responsible for the dissolve effect.
And it's really because we get an emissive color for the glow and that's nice and properly masked out
according to some noise magic that we do here that gives us that golden glow.
And there's that color for that golden glow right there.
And then we have this opacity mask right here going into opacity mask.
And as we change this parameter called Dissolve, we're changing.
Here it is.
Dissolve right here.
We're changing how much is added to this texture sample, which is just noise.
So if we use this dissolve effect material instance, we can choose to dissolve any given material if
it uses something similar to the nodes in here.
And that's why this right here, this little section is in its own comment because it's designed to
be copied and pasted into a material.
If you'd like that material to be dissolvable.
Now, notice it even has a couple of things up here on the comment.
It says Surface masked default lit.
It's telling you about some of the settings that you need.
So we need a masked material.
Let's see what this looks like.
If we apply it to our goblin material.
If I click on the Goblin and choose its skeletal mesh here in the Details panel, let's select Mesh
and browse to that.
Here's our folder with the goblin and in the materials folder here we have M underscore Goblin and actually
take a look.
We already have an M Goblin dissolve material.
If we open that, then we have some of those nodes from the dissolve effect here.
Looks like we have one going into Emissive color and we have another one going into opacity mask.
So these are essentially the same thing that we saw in that M dissolve effect.
They just happen to be pasted in here.
They are these nodes up here looks like we're using a different texture sample, but that's okay.
Same principle applies.
So this M Goblin Dissolve exists here for us and it looks like we have a material instance created from
that and we can even see what this looks like with a preview mesh.
If we go back to Goblin Select Xxm Goblin with that selected in the content browser, we can click on
the rightmost icon at the bottom right of the viewport and that will give us a preview mesh to preview
this material and we can see what it looks like and we can change the dissolve amount and see this mesh
dissolve and it looks pretty cool.
So this is what I'd like to do is I'd like to change this dissolve parameter at runtime smoothly when
the enemy dies.
Now currently the enemy is not using this dissolve material instance.
We can go to the Xxm Goblin and open it and in the asset details we see it's just using M Goblin.
So when the enemy dies, we need to set its material to that material instance.
But specifically we need to create something called a dynamic material instance.
A dynamic material instance can have its parameters dynamically changed at runtime, and I'd like to
do that.
So we have a couple of things we need to do, and we're going to start in the C plus plus domain.
So I'm going to close out of the editor.
Looks like it says you've changed a material, right?
Because I moved some things around.
I'm not going to save any of those changes.
It's going to ask if I'd like to.
I'm not going to save anything that I did.
So what I'd like to do is go to our character base, and Ora character base is going to need a couple
of things.
It's going to need a material instance that we can set as a variable.
We can set it to that, dissolve material.
So I'm going to go into the protected section, scroll down to the bottom.
I'm going to make a comment here that says Dissolve effects and we're going to have a T object pointer.
Storing a new material instance.
And I'm going to call this dissolve material instance and I'm going to have this something we can set
from the blueprint with edit anywhere, and we'll go ahead and make it blueprint read only as well.
So we have a dissolve material instance, but I'd like a way to create a dynamic material instance based
on this and swap out our enemies material.
In fact, this is on or a character base.
So we'll just say swap out our character's mesh material.
Now they also have a weapon skeletal mesh, right?
So let's have two dissolved material instances.
We'll have one for the mesh itself and one for the weapon.
So we'll call this second one weapon dissolve material instance.
Now I'd like to have a function to dissolve this thing, so I'm going to make a function void dissolve
and this function is going to swap out the material.
It's going to create a dynamic material instance based on these material instances, one for each one,
and swap out those materials on the mesh and the weapon.
And then I'd like to start a timeline.
And timelines are much easier to implement in Blueprint.
This is definitely one of those cases where it makes more sense to do it in Blueprint.
We've done timelines in C plus plus in my multiplayer shooter course If you'd like to do it that way,
check out that course, but we're going to make a timeline in blueprint, and that means I'd like a
blueprint implementable event.
So I'm going to make a void function called Start Dissolve timeline.
And this is going to take that dynamic material instance that we're going to create and the timeline
is going to update parameters on that dynamic material instance.
Now, the type for a dynamic material instance is you material instance dynamic.
So this is going to take a pointer of one of those and this will be called Dynamic material instance.
Now this is going to be a blueprint, implementable event.
So we're going to make it a new function blueprint, implementable event.
So we're not even going to implement this here in C plus plus we're going to implement it in the blueprint.
But dissolve is something we need to implement here.
So what are we going to do when we call dissolve?
Well, what I want to do is check to make sure my dissolve material instance is valid.
So we're going to say if is valid, dissolve material instance.
So if it is valid, then what are we going to do?
Well, we need to make a dynamic material instance based on this material instance.
We can do that by making a new material instance dynamic pointer.
We're going to call this dynamic mat inst.
I'll just call it that.
And we can use the static function you material instance dynamic create.
This is a creation function, a factory, if you will, and this requires the material instance.
So that's going to be desolve material instance.
And it needs an outer object.
We're just going to pass in this.
This character for that.
So this creates the dynamic material instance, but we need to set the character's mesh.
So we're going to get the mesh and we're going to call set material on it.
Now, a mesh can have multiple indices for its material.
It can have multiple materials.
So if your mesh has, say, 4 or 5 materials, then you'll need to do this for each of those materials.
Some meshes have a lot of materials, so you'll have to have a dynamic material instance for each of
those materials.
In my case, I just have a single material.
So I'm going to use the first index because that's the index for a single material.
It's going to be zero and we're going to pass in dynamic Mat inst.
So we're now setting the material on the mesh to this dynamic material instance that we'll create based
on our material instance that will set from the editor.
Now as soon as we do that, I want to call my blueprint implementable event, start, dissolve timeline,
and this takes a dynamic material instance we're going to pass in our dynamic mat inst.
And so that's going to take care of our mesh.
But we want to do this for the weapon as well.
So we're also going to say if is valid weapon dissolve material instance and if that is valid, we'll
do the same exact thing here.
So we'll copy these lines, except we're going to use weapon dissolve material instance and instead
of our character mesh, we're going to use our weapon, we're going to call weapon set material, and
then we'll start the dissolve timeline with this dynamic material instance.
Okay, So now we need to decide how that timeline behaves and we'll need to set those material instances
in the editor.
So we just need to make sure to call dissolve.
And this is something we want to call both on local machines and on the server machine.
So we're going to place this in our multicast handle death function that should be up here somewhere.
Here it is multicast handle death.
We're going to call dissolve.
So now we can compile and launch and set that material instance for each goblin and create the timeline.
Okay.
So I'm going to click open.
Now we know that we have this my goblin dissolve and we've already seen what it looks like with a preview
mesh.
We can take that SQM goblin and click on this icon here to see.
And if we click, dissolve and drag all the way to the left to about, oh -0.1 or so, we know that
it's completely full.
And if we drag to the right to about, say, 0.6 or so, 0.55, 0.6, then it's completely dissolved.
So we want to start a timeline from some value around right here, -0.0 to -0.1 or so and have it smoothly
go all the way up to about 0.5 or 0.55 or so.
Now I'd like to implement this on the base enemy class.
That way all enemies will inherit this.
So I'm going to go into character and open up enemy base, open that event graph and we have a blueprint,
implementable event to implement and it's called Start Dissolve Timeline.
And this takes a dynamic material instance.
So as soon as this gets called, I'd like a timeline.
So I'm going to make one.
So I'm going to scroll down to add timeline, and this will be called Dissolve Timeline.
So let's open this and add a track.
It's going to be a float track and we'll call this dissolve track.
And we just need a couple points on this track.
We're going to add a key by right clicking, adding a key, and at time zero, we're going to have our
value at -0.1 because on this dissolve material, that's about where we're at.
It's actually about zero really.
But a little past that is a -0.1.
That can be where our timeline starts.
Now we're going to add another point.
Add key, and this will be some point in the future, let's say three seconds later.
And where do we want to be on the dissolve curve?
Well, if we scroll forward to about 0.5, maybe 0.55, that's where we'll be completely dissolved.
So we're going to have this at 0.55.
Now I can click on Zoom to Fit Vertical and zoom to Fit Horizontal to see both of these and I can select
both key points, right click and select Auto and we have a nice smooth curve.
So now this timeline we can use to update this dynamic material instance.
So we're going to hook this up to play.
We're going to take the dynamic material instance I'm going to drag down here and type RA for Root Node.
I'm going to reroute it around the timeline and come back up here.
And we want to set a dynamic material parameter.
So I'm going to type set material parameter and the function I want is set scalar parameter value,
and this requires a parameter name.
So if we look at our material instance Goblin dissolve, the parameter is called Dissolve.
So we can stick in, dissolve here and the value is going to be the result of the dissolve track.
So every update we're calling set scalar parameter value.
So we're calling this When the enemy Dies, we can test this out by killing the enemy and seeing if
that material instance is swapped out.
Now, of course, we have to set that material instance on each enemy, right?
So here's the goblin sphere.
We can browse to it and search for Dissolve and we have a dissolve material instance.
I'm going to search for my goblin and here's my goblin dissolve.
Now do we have one for the sphere?
Let's check.
Let's go to content assets.
Enemies.
Goblin.
Spear.
Now here's the spear.
Here's a materials folder.
And look at that.
We have an m sphere dissolve and an MI sphere dissolve material instance.
And if we mess around with the dissolve parameter, we can see it dissolving and it looks like this
one has even a glow color parameter that can be changed.
So we're going to set this to my sphere, dissolve on the goblin sphere.
So my underscore sphere dissolve.
So that will take care of the spear Goblin.
Let's go back to Goblin and go to Slingshot and go to materials.
And here we have a red and green folder.
And in the red folder we have an slingshot red dissolve material and we can open the m I slingshot red,
dissolve material and it looks like this is a material for the slingshot.
So if we go to Goblin Slingshot and Centered, here's the actual slingshot.
We can preview this.
In the material instance and mess with the dissolve parameter so we can set this material on the Slingshot
goblin as well.
I'm just going to click one in the editor, browse to the asset and open its blueprint and search for
Dissolve.
So I'm going to search for my underscore goblin and we're going to use Goblin Dissolve for the body
and m I underscore slingshot read dissolve for the weapon.
All right, so we've just set those.
Let's see what happens if we kill an enemy.
So I'm going to get an enemy down to zero health.
And.
Looks like the weapon dissolved, but our mesh did not.
So we do have an issue here.
It looks to me like we can't share that timeline, so we have to go back to the base enemy and we're
going to need to have a separate timeline as these can't both be running at the same time.
If we start one with one dynamic material instance and then start another, which we're starting the
weapon second, well, we can't share the two.
So we need two different blueprint, implementable events, one called Start, dissolve timeline, and
then one for perhaps the weapon.
So we'll just really quickly make one of those.
We'll go to Aura Character Base and we'll copy the start, dissolve timeline and we'll go ahead and
just paste it and we'll call this start Weapon dissolve timeline and we'll call this one for the weapon.
So we'll go back to or a character based CP and go back down to the dissolve function.
And here instead of start dissolve timeline, we'll start weapon dissolve timeline and we'll implement
that separately.
So let's go ahead and go back into the editor.
And we'll go ahead and open up our enemy blueprint for BP enemy base.
And let's implement start weapon dissolve timeline and we'll make a separate timeline.
So let's right click type timeline.
We'll scroll down and add timeline.
We'll call this weapon dissolve timeline.
We'll double click it, add a track, it'll be a float track called Weapon Dissolve Track, and we'll
have a key here.
Starting at Time zero, we'll be at -0.1.
And for the weapon, we can dissolve a little quicker.
Let's add another key and this one will say, be at two seconds and we'll go up to 0.55.
And just because I can, I'm going to highlight both keys and select auto.
So we have a smooth curve.
And here in the event graph, we'll hook this up.
We'll add a reroute node to go around here.
And I'm just going to take the node from above Ctrl D and duplicate it.
Hook it up to update.
Hook this up and hook up.
Weapon dissolve track to value.
And now we have two separate timelines.
So let's see how this works.
And there goes The Dissolve.
Our curves are working separately and it's looking really, really nice.
There it goes.
The enemy and the weapon as well.
And we know that their life spans are being set to five.
We've seen those disappear after five seconds.
So that works as well.
So that's a really nice touch.
And if you don't have dissolve materials for a specific enemy, you can always go to the materials here
in content assets, materials.
You can take this dissolve effect and copy this section right here and hook up the two emissive color
part to the emissive color that's for the glow part of the material.
And you can hook up the two opacity mask.
To the opacity mask and just make sure the material has these qualities to it.
If we go to Im Goblin Dissolve, you'll see that in the details.
Panel Material domain is surface blend mode is masked, shading model is default lit.
Going back to that, im dissolve we see dissolve effect surface masked default lit.
Those are those parameters there.
So this can be easily copied and pasted into really any material that you want to use it for.
Great.
So now we have a nice dissolve effect for when we kill enemies and it looks a lot better than having
them just disappear.
Excellent job.
I'm going to go ahead and close down all the tabs, saving everything like so.
Close down and save all.
And I'll see you in the next video.