WEBVTT

00:06.950 --> 00:08.030
Welcome back.

00:08.030 --> 00:09.980
Now our loot is looking pretty nice.

00:09.980 --> 00:17.210
If we spawn our loot in, we have some nice dynamic effects for those potions and those crystals and

00:17.210 --> 00:18.260
they look great.

00:18.680 --> 00:23.240
Now the only thing missing is sound and we're going to handle that in this video.

00:23.240 --> 00:31.580
Now the Aura Effect Actor C plus plus class really could have a spawning or creation sound, and it

00:31.580 --> 00:33.560
can have a consume sound.

00:33.560 --> 00:38.030
But as far as hitting the ground, that's something that pickups specifically have.

00:38.030 --> 00:40.490
So that could be something in our pickup base class.

00:40.490 --> 00:43.010
And we can handle that right here in blueprint.

00:43.010 --> 00:45.650
First thing we can add a new variable.

00:45.650 --> 00:49.160
We can call this ground impact sound.

00:49.460 --> 00:53.330
And we can set this to sound base.

00:54.680 --> 00:59.450
Object reference and we can take a look at content assets.

00:59.690 --> 01:01.040
Sounds.

01:01.900 --> 01:02.620
Potions.

01:02.620 --> 01:03.010
Look at that.

01:03.010 --> 01:05.260
We have potions and we have hit ground.

01:05.260 --> 01:06.580
And here's a sound.

01:07.000 --> 01:13.000
So I'm going to take this and go to pick up base and set ground impact sound to this.

01:13.860 --> 01:20.940
And we know when we hit the ground, it's when this particular timeline has finished, or at least when

01:20.940 --> 01:23.220
it hits about this part right here.

01:23.220 --> 01:26.280
This is point eight in the graph.

01:26.280 --> 01:30.270
And we can even just check this elevation curve.

01:30.270 --> 01:33.270
We could see if it's point eight and just play a sound.

01:33.270 --> 01:41.760
If that's the case, by moving these things out a bit, moving these nodes down a bit and checking if

01:41.760 --> 01:50.430
elevation is greater than point eight, and if it is, we can play a sound.

01:51.150 --> 01:53.340
Now I want to use a do once.

01:53.910 --> 01:56.340
That way we'll only play the sound once.

01:58.820 --> 02:04.490
And on update, we'll check the branch and whether this is true or false.

02:04.490 --> 02:11.330
And we should probably actually do this after setting actor scale 3D.

02:11.330 --> 02:12.500
So here's what I'm going to do.

02:12.500 --> 02:14.900
I'm going to take elevation and promote to a variable.

02:15.870 --> 02:17.490
We'll call it elevation.

02:18.510 --> 02:22.860
Let's keep this clean here and we'll use elevation here.

02:24.670 --> 02:29.830
See if it's greater than 0.8 and use a do once all the way at the end here.

02:32.530 --> 02:34.960
That'll give us a lot less messiness.

02:34.960 --> 02:41.230
And we can plug elevation in here as well and avoid crisscrossing that wire there.

02:41.230 --> 02:43.540
So we just have one little cross.

02:46.350 --> 02:47.970
We can even promote scale.

02:47.970 --> 02:49.590
Let's just promote scale.

02:53.560 --> 02:55.330
And get rid of this one as well.

02:55.330 --> 02:56.620
That's going to be.

02:57.300 --> 02:59.250
Annoying otherwise.

03:00.840 --> 03:01.590
There.

03:03.820 --> 03:05.350
That's much better.

03:05.530 --> 03:06.670
Now.

03:07.830 --> 03:10.380
We can hook these up.

03:15.710 --> 03:20.420
And after doing these each update, then we're going to check.

03:20.420 --> 03:21.980
We're going to see.

03:22.700 --> 03:27.560
If elevation is greater than 0.8, and if so, we'll use a do once.

03:27.560 --> 03:32.570
So we only ever do this once and we'll play sound at location.

03:33.440 --> 03:35.750
We'll use get actor location.

03:37.270 --> 03:42.190
For the location and we'll use our ground impact sound for the sound.

03:42.220 --> 03:44.620
Let's try this now.

03:44.740 --> 03:49.810
All of our pickups are going to have the same ground impact sound, so it might sound funny when those

03:49.810 --> 03:55.150
crystals hit the ground, but of course, we could just go in there and change those sounds for those

03:55.150 --> 03:56.800
blueprints if we wanted to.

03:57.670 --> 03:59.920
Let's just see how this works, though.

04:09.140 --> 04:14.480
Now, it's kind of hard to tell when those sounds are playing relative to the location.

04:14.480 --> 04:21.200
So I'm going to go into ability system data and loot tiers and only spawn health potions.

04:21.200 --> 04:29.150
For now, I'm going to set the spawn chance to zero for the others and only spawn a single potion.

04:29.150 --> 04:35.750
That way I can see a little bit better when that sound is playing relative to when it drops.

04:35.780 --> 04:37.280
Didn't see a potion.

04:39.920 --> 04:41.300
Didn't get a potion.

04:41.960 --> 04:43.370
So BP.

04:43.400 --> 04:44.090
Health potion.

04:44.090 --> 04:44.990
Chance to spawn.

04:44.990 --> 04:46.490
Max number to spawn.

04:46.490 --> 04:48.770
Do I have an off by one error?

04:48.770 --> 04:50.030
I'm going to try to.

04:51.480 --> 04:53.850
Okay, I have an off by one error.

04:53.850 --> 04:54.720
We'll need to fix that.

04:54.720 --> 04:55.530
But.

04:57.840 --> 05:05.430
It looks like I'm playing the sound too early, and that's because I'm checking the value, not the

05:05.430 --> 05:06.210
time.

05:06.630 --> 05:09.660
It's the time that's point eight, not the value.

05:09.660 --> 05:15.750
So the easiest way, I think, would be to check if the value is less than zero, because it only becomes

05:15.750 --> 05:22.380
less than zero right around here, we can even go a little bit less than that value.

05:22.380 --> 05:25.590
So we could say if elevation is less than.

05:27.390 --> 05:29.040
We'll go to like negative.

05:30.100 --> 05:30.670
Let's see.

05:30.670 --> 05:32.410
Negative point.

05:33.070 --> 05:35.710
One because we go all the way down to negative point two.

05:35.740 --> 05:39.490
So let's see if we're down below negative point one.

05:44.310 --> 05:47.100
And then we should play that at the correct time.

05:51.250 --> 05:53.560
Yeah, that looks good and sounds good.

05:53.800 --> 05:56.110
Okay, so that takes care of that sound.

05:56.140 --> 05:58.810
Now let's fix that off by one error.

05:58.810 --> 06:01.390
We had max number to spawn set at two.

06:01.420 --> 06:05.530
We're going to need to see what's going on when we're spawning.

06:05.530 --> 06:08.770
Let's go over to blueprints character.

06:10.310 --> 06:11.900
BP enemy base.

06:12.860 --> 06:14.780
Where we're spawning.

06:17.430 --> 06:20.430
Right here in spawn loot item.

06:20.430 --> 06:22.920
We're checking spawn loop count now.

06:22.920 --> 06:30.720
We should be fine if we exit as long as spawn loop count is less than loot items length, we shouldn't

06:30.720 --> 06:33.000
have to subtract one from this.

06:34.240 --> 06:37.450
But we did see that we were getting errors when we didn't.

06:37.480 --> 06:42.250
Let's see if we can figure out why we are getting those two potions.

06:44.180 --> 06:45.590
But when are we accessing?

06:45.590 --> 06:46.130
None.

06:46.130 --> 06:52.100
We're attempting to access index two from array of loot items of length two.

06:52.250 --> 06:58.250
So we're accessing the index of the third item in a two item array.

06:58.250 --> 07:01.070
We should never try to access index two right.

07:01.070 --> 07:05.600
So let's get that error back and see exactly where the violation is occurring.

07:05.600 --> 07:10.640
We can figure this out if we go ahead and get some loot spawning.

07:12.350 --> 07:19.820
Escape here and we can look at our error and it says it's on a branch.

07:19.820 --> 07:21.530
So we're getting this branch.

07:21.530 --> 07:25.940
We're getting the boolean value from here which is getting spawn loop count.

07:25.940 --> 07:29.930
And it looks like we're doing this after incrementing spawn loop count.

07:29.930 --> 07:31.520
So there's the violation.

07:31.520 --> 07:36.080
So we actually need to increment spawn loop count after.

07:36.080 --> 07:38.300
So that's okay.

07:38.300 --> 07:39.500
We can do that.

07:41.320 --> 07:49.210
But we have to increment spawn loop count regardless of whether the cast fails or succeeds, and regardless

07:49.210 --> 07:51.880
of the value of true or false here.

07:51.880 --> 07:52.900
And you know what?

07:52.900 --> 07:57.550
This cast failed is enough to check the validity.

07:57.580 --> 08:01.210
We only need to continue if the cast succeeds.

08:01.210 --> 08:03.040
Is valid is unnecessary.

08:03.870 --> 08:06.060
The cast will take care of that for us.

08:06.060 --> 08:12.630
So if the cast fails, we're still going to increment the loop count and we're still going to increment

08:12.630 --> 08:14.490
it whether this is true or false.

08:14.490 --> 08:20.790
So all of these cases will result in the incrementing of the loop count.

08:20.790 --> 08:23.370
Bit of an ugly bunch of nodes here.

08:23.370 --> 08:26.490
But that's okay I'm just going to stick this right here.

08:27.630 --> 08:30.690
And we can clean that up later, but let's make sure.

08:31.390 --> 08:37.030
That this eliminates the error, and that we also get two potions when we should get two.

08:45.350 --> 08:47.060
We get two and no errors.

08:47.060 --> 08:47.780
Perfect.

08:47.900 --> 08:55.670
Okay, so with that, we're now playing a sound when our pickups hit the ground.

08:55.670 --> 09:03.560
But our Aura Effect actor can have an on spawn sound and a consumed sound if we like, so we can add

09:03.560 --> 09:06.620
that right in to Aura Effect actor.

09:06.620 --> 09:09.980
Now add that to the C plus plus class if you like.

09:09.980 --> 09:16.370
But really I only care about pickups, so I'm just actually going to add this right here in the blueprint.

09:16.370 --> 09:20.450
We'll play a spawn sound on Begin Play.

09:20.450 --> 09:22.310
So we'll go ahead and add a variable.

09:22.310 --> 09:23.600
It'll be a sound base.

09:23.600 --> 09:25.940
We'll say spawn sound.

09:26.570 --> 09:34.400
And I'm just going to copy play sound at location with Get Actor location and we'll get one here.

09:34.400 --> 09:36.110
We'll use our spawn sound.

09:36.850 --> 09:46.150
We'll compile and give this a default value and we'll go into content assets, sounds potions, spawn,

09:46.150 --> 09:47.710
and we have a spawn sound.

09:48.770 --> 09:50.420
I'm going to get that.

09:51.670 --> 09:52.870
And set it here.

09:53.290 --> 09:56.350
And then finally on consume.

09:56.350 --> 09:59.770
We need to know when our potion is destroyed.

09:59.770 --> 10:01.360
We can just use event.

10:01.360 --> 10:02.320
Destroy.

10:02.350 --> 10:03.820
Event destroyed.

10:04.090 --> 10:07.810
And we can copy play sound at location.

10:07.810 --> 10:10.330
And we can have a consumed sound.

10:10.330 --> 10:14.950
We'll promote this to a variable called consumed sound.

10:15.600 --> 10:19.770
We'll compile and we'll give this a default value as well.

10:20.890 --> 10:24.730
And in potions we have consume.

10:26.100 --> 10:27.480
Let's use that.

10:30.240 --> 10:31.320
There we go.

10:33.810 --> 10:37.020
And with that, we can test out these sounds.

10:46.820 --> 10:47.330
All right.

10:47.330 --> 10:48.080
They sound great.

10:48.080 --> 10:49.340
Let's consume them.

10:51.370 --> 10:52.420
Perfect.

10:52.420 --> 10:53.860
That looks great.

10:53.890 --> 10:57.520
So now I'm going to lower the chance to spawn these.

10:57.520 --> 11:05.470
I'm going to lower the chance to spawn a health potion to 20%, and a mana potion also to 20%.

11:06.400 --> 11:09.280
And I'm going to consider the crystals much more rare.

11:09.280 --> 11:17.980
We'll give the health crystal and mana crystal a 5% chance to spawn two of them each, and health potion

11:17.980 --> 11:19.330
will be three.

11:20.020 --> 11:23.320
Max and mana will be three max.

11:23.320 --> 11:27.040
And with that, we'll see those potions.

11:27.040 --> 11:31.180
But not for every enemy, not every time.

11:36.740 --> 11:38.180
So there was one.

11:41.520 --> 11:42.930
And there was one.

11:44.050 --> 11:45.070
Excellent.

11:46.370 --> 11:47.150
All right.

11:47.150 --> 11:47.960
Awesome job.

11:47.960 --> 11:51.500
We now have some really cool looking and sounding potions and pickups.

11:51.500 --> 11:57.440
This adds quite a bit to our game, and you can use this same technique for any types of pickups you

11:57.440 --> 11:58.130
like.

11:58.220 --> 12:06.410
Okay, a little bit of testing and I do get an error trying to set actor level because we're trying

12:06.410 --> 12:08.450
to set the actor level here.

12:08.480 --> 12:10.160
On aura effect actor.

12:10.160 --> 12:14.810
Whether or not that actor is valid, it could be pending kill.

12:14.810 --> 12:22.730
So setting the actor level actually needs to be done if the actor is valid, and only if the actor is

12:22.730 --> 12:23.480
valid.

12:23.480 --> 12:30.770
So what we can do is move this set actor level right here.

12:31.530 --> 12:35.250
And only do it if that actor is valid.

12:35.850 --> 12:36.930
Like so.

12:45.660 --> 12:46.710
There we go.
