WEBVTT

00:06.990 --> 00:08.160
Welcome back.

00:08.250 --> 00:09.750
Now we have death working.

00:09.750 --> 00:15.170
And if we get our enemies down to zero health, we know that we can rag doll them.

00:15.180 --> 00:20.220
Now, in this video, I'm concerned with a little bit extra of an effect.

00:20.220 --> 00:22.350
I'd like to dissolve the enemy.

00:22.350 --> 00:24.200
So what do I mean by dissolve?

00:24.210 --> 00:27.930
Well, let me go ahead and close down any of those tabs I don't need.

00:27.930 --> 00:33.510
And let's take a look in our assets folder into materials.

00:33.540 --> 00:37.380
Notice I have something called M Dissolve Effect.

00:37.500 --> 00:39.720
Let's take a look at this material.

00:39.720 --> 00:41.550
Here's what it looks like now.

00:41.550 --> 00:46.410
This has a number of material parameters and by number I mean two.

00:46.410 --> 00:50.130
Let's open my dissolve effect and check it out.

00:50.160 --> 00:52.050
We have dissolve and glow.

00:52.050 --> 00:58.110
Now Glow is going to make those edges glow just a bit more or less, depending on the value.

00:58.110 --> 01:00.840
But look at the dissolve parameter.

01:00.840 --> 01:03.870
If I click and drag to the right, it dissolves away.

01:03.870 --> 01:07.600
If I drag to the left, then the material comes back.

01:07.690 --> 01:13.960
Now if we look in m dissolve effect, we see that it's just a base color and that's this pink color.

01:13.960 --> 01:16.120
That's why it looks pink like this.

01:16.120 --> 01:19.090
But then we also have this little bit here.

01:19.090 --> 01:22.990
This is what's responsible for the dissolve effect.

01:22.990 --> 01:30.760
And it's really because we get an emissive color for the glow and that's nice and properly masked out

01:30.760 --> 01:35.200
according to some noise magic that we do here that gives us that golden glow.

01:35.200 --> 01:38.110
And there's that color for that golden glow right there.

01:38.110 --> 01:44.230
And then we have this opacity mask right here going into opacity mask.

01:44.230 --> 01:50.140
And as we change this parameter called Dissolve, we're changing.

01:50.140 --> 01:50.800
Here it is.

01:50.800 --> 01:51.730
Dissolve right here.

01:51.730 --> 01:57.430
We're changing how much is added to this texture sample, which is just noise.

01:57.880 --> 02:06.580
So if we use this dissolve effect material instance, we can choose to dissolve any given material if

02:06.580 --> 02:09.880
it uses something similar to the nodes in here.

02:09.880 --> 02:17.950
And that's why this right here, this little section is in its own comment because it's designed to

02:17.950 --> 02:20.890
be copied and pasted into a material.

02:20.890 --> 02:24.250
If you'd like that material to be dissolvable.

02:24.460 --> 02:27.730
Now, notice it even has a couple of things up here on the comment.

02:27.730 --> 02:31.120
It says Surface masked default lit.

02:31.150 --> 02:33.790
It's telling you about some of the settings that you need.

02:33.790 --> 02:36.420
So we need a masked material.

02:36.430 --> 02:37.840
Let's see what this looks like.

02:37.840 --> 02:40.690
If we apply it to our goblin material.

02:40.690 --> 02:48.760
If I click on the Goblin and choose its skeletal mesh here in the Details panel, let's select Mesh

02:48.760 --> 02:50.800
and browse to that.

02:50.830 --> 02:58.460
Here's our folder with the goblin and in the materials folder here we have M underscore Goblin and actually

02:58.460 --> 02:59.270
take a look.

02:59.270 --> 03:02.030
We already have an M Goblin dissolve material.

03:02.030 --> 03:10.280
If we open that, then we have some of those nodes from the dissolve effect here.

03:10.400 --> 03:17.480
Looks like we have one going into Emissive color and we have another one going into opacity mask.

03:17.480 --> 03:23.930
So these are essentially the same thing that we saw in that M dissolve effect.

03:23.960 --> 03:26.450
They just happen to be pasted in here.

03:26.480 --> 03:32.390
They are these nodes up here looks like we're using a different texture sample, but that's okay.

03:32.390 --> 03:34.460
Same principle applies.

03:34.640 --> 03:42.530
So this M Goblin Dissolve exists here for us and it looks like we have a material instance created from

03:42.560 --> 03:46.610
that and we can even see what this looks like with a preview mesh.

03:46.610 --> 03:53.960
If we go back to Goblin Select Xxm Goblin with that selected in the content browser, we can click on

03:53.960 --> 03:59.900
the rightmost icon at the bottom right of the viewport and that will give us a preview mesh to preview

03:59.900 --> 04:06.470
this material and we can see what it looks like and we can change the dissolve amount and see this mesh

04:06.470 --> 04:08.690
dissolve and it looks pretty cool.

04:08.690 --> 04:17.630
So this is what I'd like to do is I'd like to change this dissolve parameter at runtime smoothly when

04:17.630 --> 04:19.190
the enemy dies.

04:19.310 --> 04:24.590
Now currently the enemy is not using this dissolve material instance.

04:24.620 --> 04:32.000
We can go to the Xxm Goblin and open it and in the asset details we see it's just using M Goblin.

04:32.150 --> 04:38.690
So when the enemy dies, we need to set its material to that material instance.

04:38.690 --> 04:43.520
But specifically we need to create something called a dynamic material instance.

04:43.550 --> 04:50.240
A dynamic material instance can have its parameters dynamically changed at runtime, and I'd like to

04:50.240 --> 04:51.020
do that.

04:51.170 --> 04:56.780
So we have a couple of things we need to do, and we're going to start in the C plus plus domain.

04:56.780 --> 04:58.880
So I'm going to close out of the editor.

04:58.910 --> 05:03.050
Looks like it says you've changed a material, right?

05:03.050 --> 05:04.490
Because I moved some things around.

05:04.490 --> 05:06.650
I'm not going to save any of those changes.

05:06.740 --> 05:08.990
It's going to ask if I'd like to.

05:09.140 --> 05:11.330
I'm not going to save anything that I did.

05:11.330 --> 05:17.900
So what I'd like to do is go to our character base, and Ora character base is going to need a couple

05:17.900 --> 05:18.770
of things.

05:18.770 --> 05:23.570
It's going to need a material instance that we can set as a variable.

05:23.570 --> 05:25.910
We can set it to that, dissolve material.

05:25.910 --> 05:30.080
So I'm going to go into the protected section, scroll down to the bottom.

05:30.590 --> 05:40.190
I'm going to make a comment here that says Dissolve effects and we're going to have a T object pointer.

05:41.380 --> 05:44.560
Storing a new material instance.

05:45.280 --> 05:53.020
And I'm going to call this dissolve material instance and I'm going to have this something we can set

05:53.020 --> 06:00.070
from the blueprint with edit anywhere, and we'll go ahead and make it blueprint read only as well.

06:00.070 --> 06:08.140
So we have a dissolve material instance, but I'd like a way to create a dynamic material instance based

06:08.140 --> 06:11.980
on this and swap out our enemies material.

06:11.980 --> 06:13.630
In fact, this is on or a character base.

06:13.630 --> 06:17.890
So we'll just say swap out our character's mesh material.

06:18.250 --> 06:21.160
Now they also have a weapon skeletal mesh, right?

06:21.160 --> 06:25.150
So let's have two dissolved material instances.

06:25.300 --> 06:29.860
We'll have one for the mesh itself and one for the weapon.

06:29.860 --> 06:34.300
So we'll call this second one weapon dissolve material instance.

06:34.390 --> 06:44.470
Now I'd like to have a function to dissolve this thing, so I'm going to make a function void dissolve

06:44.470 --> 06:47.990
and this function is going to swap out the material.

06:47.990 --> 06:55.310
It's going to create a dynamic material instance based on these material instances, one for each one,

06:55.310 --> 06:58.580
and swap out those materials on the mesh and the weapon.

06:58.580 --> 07:01.460
And then I'd like to start a timeline.

07:01.460 --> 07:05.870
And timelines are much easier to implement in Blueprint.

07:05.900 --> 07:11.630
This is definitely one of those cases where it makes more sense to do it in Blueprint.

07:11.660 --> 07:17.210
We've done timelines in C plus plus in my multiplayer shooter course If you'd like to do it that way,

07:17.210 --> 07:22.250
check out that course, but we're going to make a timeline in blueprint, and that means I'd like a

07:22.250 --> 07:24.230
blueprint implementable event.

07:24.260 --> 07:29.660
So I'm going to make a void function called Start Dissolve timeline.

07:31.000 --> 07:38.830
And this is going to take that dynamic material instance that we're going to create and the timeline

07:38.830 --> 07:43.600
is going to update parameters on that dynamic material instance.

07:43.600 --> 07:49.670
Now, the type for a dynamic material instance is you material instance dynamic.

07:49.720 --> 07:56.410
So this is going to take a pointer of one of those and this will be called Dynamic material instance.

07:57.330 --> 08:00.330
Now this is going to be a blueprint, implementable event.

08:00.330 --> 08:05.220
So we're going to make it a new function blueprint, implementable event.

08:05.610 --> 08:10.890
So we're not even going to implement this here in C plus plus we're going to implement it in the blueprint.

08:10.890 --> 08:14.130
But dissolve is something we need to implement here.

08:14.640 --> 08:17.730
So what are we going to do when we call dissolve?

08:17.730 --> 08:23.790
Well, what I want to do is check to make sure my dissolve material instance is valid.

08:23.790 --> 08:28.380
So we're going to say if is valid, dissolve material instance.

08:29.110 --> 08:32.650
So if it is valid, then what are we going to do?

08:32.680 --> 08:38.080
Well, we need to make a dynamic material instance based on this material instance.

08:38.110 --> 08:43.630
We can do that by making a new material instance dynamic pointer.

08:43.660 --> 08:47.680
We're going to call this dynamic mat inst.

08:47.710 --> 08:48.970
I'll just call it that.

08:49.210 --> 08:56.080
And we can use the static function you material instance dynamic create.

08:56.110 --> 09:02.770
This is a creation function, a factory, if you will, and this requires the material instance.

09:02.770 --> 09:05.860
So that's going to be desolve material instance.

09:08.300 --> 09:10.100
And it needs an outer object.

09:10.100 --> 09:11.990
We're just going to pass in this.

09:12.110 --> 09:14.300
This character for that.

09:14.570 --> 09:19.940
So this creates the dynamic material instance, but we need to set the character's mesh.

09:19.940 --> 09:27.140
So we're going to get the mesh and we're going to call set material on it.

09:27.620 --> 09:31.580
Now, a mesh can have multiple indices for its material.

09:31.580 --> 09:33.350
It can have multiple materials.

09:33.680 --> 09:41.480
So if your mesh has, say, 4 or 5 materials, then you'll need to do this for each of those materials.

09:41.480 --> 09:47.960
Some meshes have a lot of materials, so you'll have to have a dynamic material instance for each of

09:47.960 --> 09:49.150
those materials.

09:49.160 --> 09:51.710
In my case, I just have a single material.

09:51.920 --> 09:57.200
So I'm going to use the first index because that's the index for a single material.

09:57.200 --> 10:02.540
It's going to be zero and we're going to pass in dynamic Mat inst.

10:03.170 --> 10:09.360
So we're now setting the material on the mesh to this dynamic material instance that we'll create based

10:09.360 --> 10:13.410
on our material instance that will set from the editor.

10:13.530 --> 10:20.430
Now as soon as we do that, I want to call my blueprint implementable event, start, dissolve timeline,

10:20.760 --> 10:28.090
and this takes a dynamic material instance we're going to pass in our dynamic mat inst.

10:28.730 --> 10:31.580
And so that's going to take care of our mesh.

10:31.580 --> 10:34.190
But we want to do this for the weapon as well.

10:34.190 --> 10:43.910
So we're also going to say if is valid weapon dissolve material instance and if that is valid, we'll

10:43.910 --> 10:45.830
do the same exact thing here.

10:45.860 --> 10:51.890
So we'll copy these lines, except we're going to use weapon dissolve material instance and instead

10:51.890 --> 10:57.980
of our character mesh, we're going to use our weapon, we're going to call weapon set material, and

10:57.980 --> 11:02.480
then we'll start the dissolve timeline with this dynamic material instance.

11:02.810 --> 11:09.770
Okay, So now we need to decide how that timeline behaves and we'll need to set those material instances

11:09.770 --> 11:10.820
in the editor.

11:11.030 --> 11:13.640
So we just need to make sure to call dissolve.

11:13.640 --> 11:19.550
And this is something we want to call both on local machines and on the server machine.

11:19.550 --> 11:26.330
So we're going to place this in our multicast handle death function that should be up here somewhere.

11:26.420 --> 11:28.860
Here it is multicast handle death.

11:28.860 --> 11:30.900
We're going to call dissolve.

11:31.230 --> 11:39.900
So now we can compile and launch and set that material instance for each goblin and create the timeline.

11:41.940 --> 11:42.330
Okay.

11:42.330 --> 11:43.740
So I'm going to click open.

11:44.570 --> 11:50.690
Now we know that we have this my goblin dissolve and we've already seen what it looks like with a preview

11:50.720 --> 11:51.350
mesh.

11:52.220 --> 11:56.740
We can take that SQM goblin and click on this icon here to see.

11:56.750 --> 12:04.700
And if we click, dissolve and drag all the way to the left to about, oh -0.1 or so, we know that

12:04.700 --> 12:06.260
it's completely full.

12:06.260 --> 12:17.420
And if we drag to the right to about, say, 0.6 or so, 0.55, 0.6, then it's completely dissolved.

12:17.540 --> 12:28.880
So we want to start a timeline from some value around right here, -0.0 to -0.1 or so and have it smoothly

12:28.880 --> 12:32.960
go all the way up to about 0.5 or 0.55 or so.

12:32.990 --> 12:37.010
Now I'd like to implement this on the base enemy class.

12:37.010 --> 12:39.550
That way all enemies will inherit this.

12:39.560 --> 12:48.140
So I'm going to go into character and open up enemy base, open that event graph and we have a blueprint,

12:48.140 --> 12:53.570
implementable event to implement and it's called Start Dissolve Timeline.

12:54.130 --> 12:56.920
And this takes a dynamic material instance.

12:57.010 --> 13:00.130
So as soon as this gets called, I'd like a timeline.

13:00.130 --> 13:01.360
So I'm going to make one.

13:02.690 --> 13:08.750
So I'm going to scroll down to add timeline, and this will be called Dissolve Timeline.

13:09.290 --> 13:11.990
So let's open this and add a track.

13:12.020 --> 13:17.100
It's going to be a float track and we'll call this dissolve track.

13:17.120 --> 13:20.150
And we just need a couple points on this track.

13:20.150 --> 13:26.690
We're going to add a key by right clicking, adding a key, and at time zero, we're going to have our

13:26.690 --> 13:36.020
value at -0.1 because on this dissolve material, that's about where we're at.

13:36.050 --> 13:39.080
It's actually about zero really.

13:39.080 --> 13:42.800
But a little past that is a -0.1.

13:42.920 --> 13:45.800
That can be where our timeline starts.

13:46.190 --> 13:48.440
Now we're going to add another point.

13:48.470 --> 13:55.520
Add key, and this will be some point in the future, let's say three seconds later.

13:55.520 --> 13:59.660
And where do we want to be on the dissolve curve?

13:59.660 --> 14:08.280
Well, if we scroll forward to about 0.5, maybe 0.55, that's where we'll be completely dissolved.

14:08.280 --> 14:10.530
So we're going to have this at 0.55.

14:10.560 --> 14:17.190
Now I can click on Zoom to Fit Vertical and zoom to Fit Horizontal to see both of these and I can select

14:17.190 --> 14:22.200
both key points, right click and select Auto and we have a nice smooth curve.

14:22.320 --> 14:28.220
So now this timeline we can use to update this dynamic material instance.

14:28.230 --> 14:30.210
So we're going to hook this up to play.

14:30.330 --> 14:37.650
We're going to take the dynamic material instance I'm going to drag down here and type RA for Root Node.

14:37.700 --> 14:42.150
I'm going to reroute it around the timeline and come back up here.

14:42.330 --> 14:46.260
And we want to set a dynamic material parameter.

14:46.260 --> 14:55.110
So I'm going to type set material parameter and the function I want is set scalar parameter value,

14:55.110 --> 14:57.510
and this requires a parameter name.

14:57.510 --> 15:02.790
So if we look at our material instance Goblin dissolve, the parameter is called Dissolve.

15:02.790 --> 15:09.300
So we can stick in, dissolve here and the value is going to be the result of the dissolve track.

15:09.300 --> 15:13.500
So every update we're calling set scalar parameter value.

15:13.920 --> 15:22.170
So we're calling this When the enemy Dies, we can test this out by killing the enemy and seeing if

15:22.170 --> 15:25.080
that material instance is swapped out.

15:25.080 --> 15:29.820
Now, of course, we have to set that material instance on each enemy, right?

15:29.820 --> 15:31.980
So here's the goblin sphere.

15:31.980 --> 15:38.490
We can browse to it and search for Dissolve and we have a dissolve material instance.

15:38.490 --> 15:44.760
I'm going to search for my goblin and here's my goblin dissolve.

15:44.790 --> 15:46.890
Now do we have one for the sphere?

15:46.920 --> 15:48.000
Let's check.

15:48.090 --> 15:50.670
Let's go to content assets.

15:50.670 --> 15:51.840
Enemies.

15:51.870 --> 15:52.980
Goblin.

15:52.980 --> 15:54.000
Spear.

15:54.030 --> 15:55.470
Now here's the spear.

15:55.500 --> 15:57.720
Here's a materials folder.

15:57.720 --> 15:58.680
And look at that.

15:58.680 --> 16:04.680
We have an m sphere dissolve and an MI sphere dissolve material instance.

16:04.680 --> 16:11.520
And if we mess around with the dissolve parameter, we can see it dissolving and it looks like this

16:11.520 --> 16:15.840
one has even a glow color parameter that can be changed.

16:15.840 --> 16:21.510
So we're going to set this to my sphere, dissolve on the goblin sphere.

16:21.510 --> 16:25.440
So my underscore sphere dissolve.

16:26.260 --> 16:28.960
So that will take care of the spear Goblin.

16:29.200 --> 16:34.690
Let's go back to Goblin and go to Slingshot and go to materials.

16:34.690 --> 16:37.360
And here we have a red and green folder.

16:37.360 --> 16:46.000
And in the red folder we have an slingshot red dissolve material and we can open the m I slingshot red,

16:46.000 --> 16:50.960
dissolve material and it looks like this is a material for the slingshot.

16:50.980 --> 16:56.800
So if we go to Goblin Slingshot and Centered, here's the actual slingshot.

16:56.830 --> 16:58.540
We can preview this.

16:59.790 --> 17:08.130
In the material instance and mess with the dissolve parameter so we can set this material on the Slingshot

17:08.160 --> 17:08.880
goblin as well.

17:08.880 --> 17:14.580
I'm just going to click one in the editor, browse to the asset and open its blueprint and search for

17:14.580 --> 17:15.330
Dissolve.

17:15.450 --> 17:22.320
So I'm going to search for my underscore goblin and we're going to use Goblin Dissolve for the body

17:22.440 --> 17:29.730
and m I underscore slingshot read dissolve for the weapon.

17:31.290 --> 17:34.010
All right, so we've just set those.

17:34.020 --> 17:37.140
Let's see what happens if we kill an enemy.

17:37.500 --> 17:41.850
So I'm going to get an enemy down to zero health.

17:42.570 --> 17:43.800
And.

17:46.210 --> 17:51.280
Looks like the weapon dissolved, but our mesh did not.

17:51.910 --> 17:54.070
So we do have an issue here.

17:54.190 --> 18:02.560
It looks to me like we can't share that timeline, so we have to go back to the base enemy and we're

18:02.560 --> 18:07.720
going to need to have a separate timeline as these can't both be running at the same time.

18:07.720 --> 18:13.390
If we start one with one dynamic material instance and then start another, which we're starting the

18:13.390 --> 18:16.410
weapon second, well, we can't share the two.

18:16.420 --> 18:22.900
So we need two different blueprint, implementable events, one called Start, dissolve timeline, and

18:22.900 --> 18:24.760
then one for perhaps the weapon.

18:25.030 --> 18:28.170
So we'll just really quickly make one of those.

18:28.180 --> 18:35.140
We'll go to Aura Character Base and we'll copy the start, dissolve timeline and we'll go ahead and

18:35.140 --> 18:43.780
just paste it and we'll call this start Weapon dissolve timeline and we'll call this one for the weapon.

18:43.780 --> 18:49.810
So we'll go back to or a character based CP and go back down to the dissolve function.

18:49.810 --> 18:55.970
And here instead of start dissolve timeline, we'll start weapon dissolve timeline and we'll implement

18:55.970 --> 18:57.500
that separately.

18:58.010 --> 19:01.250
So let's go ahead and go back into the editor.

19:02.410 --> 19:07.900
And we'll go ahead and open up our enemy blueprint for BP enemy base.

19:07.900 --> 19:14.530
And let's implement start weapon dissolve timeline and we'll make a separate timeline.

19:14.530 --> 19:18.100
So let's right click type timeline.

19:18.730 --> 19:21.160
We'll scroll down and add timeline.

19:21.160 --> 19:25.780
We'll call this weapon dissolve timeline.

19:26.590 --> 19:34.360
We'll double click it, add a track, it'll be a float track called Weapon Dissolve Track, and we'll

19:34.360 --> 19:35.680
have a key here.

19:35.680 --> 19:40.270
Starting at Time zero, we'll be at -0.1.

19:40.270 --> 19:44.260
And for the weapon, we can dissolve a little quicker.

19:44.260 --> 19:52.000
Let's add another key and this one will say, be at two seconds and we'll go up to 0.55.

19:52.150 --> 19:57.490
And just because I can, I'm going to highlight both keys and select auto.

19:57.490 --> 19:59.170
So we have a smooth curve.

19:59.380 --> 20:02.360
And here in the event graph, we'll hook this up.

20:02.360 --> 20:06.560
We'll add a reroute node to go around here.

20:08.920 --> 20:14.230
And I'm just going to take the node from above Ctrl D and duplicate it.

20:14.260 --> 20:15.730
Hook it up to update.

20:16.120 --> 20:18.040
Hook this up and hook up.

20:18.040 --> 20:20.420
Weapon dissolve track to value.

20:20.440 --> 20:23.230
And now we have two separate timelines.

20:23.230 --> 20:24.940
So let's see how this works.

20:31.860 --> 20:35.310
And there goes The Dissolve.

20:35.430 --> 20:41.400
Our curves are working separately and it's looking really, really nice.

20:41.430 --> 20:42.090
There it goes.

20:42.090 --> 20:46.700
The enemy and the weapon as well.

20:46.710 --> 20:49.650
And we know that their life spans are being set to five.

20:49.680 --> 20:53.340
We've seen those disappear after five seconds.

20:53.340 --> 20:54.720
So that works as well.

20:54.810 --> 20:56.820
So that's a really nice touch.

20:57.000 --> 21:06.180
And if you don't have dissolve materials for a specific enemy, you can always go to the materials here

21:06.180 --> 21:08.420
in content assets, materials.

21:08.430 --> 21:17.190
You can take this dissolve effect and copy this section right here and hook up the two emissive color

21:17.190 --> 21:21.180
part to the emissive color that's for the glow part of the material.

21:21.180 --> 21:24.300
And you can hook up the two opacity mask.

21:24.900 --> 21:30.540
To the opacity mask and just make sure the material has these qualities to it.

21:30.660 --> 21:36.270
If we go to Im Goblin Dissolve, you'll see that in the details.

21:36.270 --> 21:43.080
Panel Material domain is surface blend mode is masked, shading model is default lit.

21:43.110 --> 21:49.380
Going back to that, im dissolve we see dissolve effect surface masked default lit.

21:49.410 --> 21:51.420
Those are those parameters there.

21:51.420 --> 21:57.360
So this can be easily copied and pasted into really any material that you want to use it for.

21:57.390 --> 21:58.140
Great.

21:58.140 --> 22:03.960
So now we have a nice dissolve effect for when we kill enemies and it looks a lot better than having

22:03.960 --> 22:05.670
them just disappear.

22:05.970 --> 22:07.020
Excellent job.

22:07.020 --> 22:13.680
I'm going to go ahead and close down all the tabs, saving everything like so.

22:14.870 --> 22:16.580
Close down and save all.

22:16.580 --> 22:18.680
And I'll see you in the next video.
