WEBVTT

00:06.930 --> 00:08.010
Welcome back.

00:08.040 --> 00:14.850
Now we have a projectile spell and a projectile, but our projectile really doesn't do anything except

00:14.850 --> 00:15.990
fly through the air.

00:16.020 --> 00:20.310
So in this video, we're going to make sure something happens when it hits something.

00:20.400 --> 00:27.450
So for that, we're going to go into actor and or a projectile and we'll open up the CPP and header

00:27.450 --> 00:30.660
files and I'm done with my combat interface.

00:30.690 --> 00:36.900
Now, yes, we're going to want to cause damage and I want to use a gameplay effect for that and we'll

00:36.900 --> 00:37.800
get to that.

00:37.800 --> 00:45.240
But for now, I'd like to at least make sure that we take care of the cosmetics involved with a projectile

00:45.240 --> 00:52.080
hitting something that's going to involve a at least effect Niagara system and a sound.

00:52.080 --> 00:58.280
So we're going to have a couple of variables on the projectile for those things and those can be private.

00:58.290 --> 01:05.040
So we're going to have a T object pointer and this will be for our Niagara system.

01:05.040 --> 01:08.830
So I'm going to use you Niagara system.

01:08.980 --> 01:16.210
Now, I'd like to include a forward declaration up there for Niagara system and I'm going to call this

01:16.240 --> 01:17.650
impact effect.

01:18.250 --> 01:20.860
Now we're using you Niagara system.

01:20.860 --> 01:29.260
So I'd better go to Aura, build X and add Niagara to my dependencies here.

01:29.260 --> 01:37.270
So I can go ahead and add that right here to my private dependency module names Niagara like so, so

01:37.270 --> 01:42.460
I can go ahead and save that, close it out and we have an impact effect.

01:42.490 --> 01:47.440
Now my impact effect is going to need a new property.

01:48.320 --> 01:50.630
And we want to set this from the blueprint.

01:50.660 --> 01:52.340
We'll make it edit anywhere.

01:52.550 --> 02:00.440
Now, in addition to the impact effect, I want a sound, so I'm going to use T object pointer of type

02:00.470 --> 02:02.300
u sound base.

02:02.840 --> 02:09.320
Use sound base will allow me to use any type of sound that I want, whether it's a sound cue or a meta

02:09.320 --> 02:09.720
sound.

02:09.740 --> 02:11.240
We're going to use meta sounds.

02:11.360 --> 02:16.580
So I'm going to call this impact sound and again, add it anywhere.

02:16.610 --> 02:18.520
So when do we play these?

02:18.530 --> 02:26.840
Well, obviously when our projectile is destroyed or when it overlaps with something, that's one circumstance.

02:26.840 --> 02:30.700
And we're going to want to destroy the projectile when it hits.

02:30.710 --> 02:31.220
Right?

02:31.220 --> 02:37.760
So here in our on overlap function, on sphere overlap, currently nothing's happening.

02:37.850 --> 02:43.130
But what I'd like to do is play the sound and spawn the effect.

02:43.160 --> 02:52.800
So to play the sound, we use gameplay statics so I can use you gameplay statics play sound at location.

02:53.310 --> 02:56.730
Now we're going to need to include gameplay statics.

02:56.730 --> 03:03.870
So let's get that up here include and it's in kismet slash gameplay statics.

03:03.910 --> 03:06.720
Not sure why Ryder didn't give me autocomplete there.

03:07.110 --> 03:11.130
Now this function requires a world context object.

03:11.160 --> 03:12.810
We'll pass in this.

03:12.840 --> 03:17.520
It also needs the sound we'll pass in impact sound.

03:17.670 --> 03:24.630
After that, we need the location, so we'll go ahead and use our actor location, get actor location.

03:24.780 --> 03:26.280
It needs a rotation.

03:26.280 --> 03:32.040
We'll just go ahead and use F rotator zero rotator.

03:32.130 --> 03:37.200
And after that it has a whole bunch of optional parameters we don't need to pass in.

03:37.530 --> 03:39.660
So that takes care of playing the sound.

03:39.660 --> 03:47.820
We also want to spawn a Niagara system and for that we use use Niagara function library and we'll use

03:47.820 --> 03:50.330
spawn system at location.

03:50.510 --> 03:54.200
Now for this, it's very much like spawn sound at location.

03:54.200 --> 03:56.450
We pass in a world context object.

03:56.450 --> 04:03.560
We pass in the impact effect for the system and we need a location and a rotation.

04:03.560 --> 04:09.470
In fact, we don't necessarily need a rotation, we just need the location and the rest are optional.

04:09.470 --> 04:11.750
So we're going to use get actor location.

04:13.570 --> 04:15.700
So this happens on overlap.

04:15.700 --> 04:21.790
And if we're on the server, I'd like to destroy the projectile, but that's something the server I

04:21.790 --> 04:23.190
think should handle.

04:23.200 --> 04:29.290
So we're going to check if has authority and if we do have authority, we're going to destroy.

04:29.530 --> 04:37.600
Now, there's a very unlikely event that this act of destruction could replicate down to the client

04:37.600 --> 04:45.070
before the client has had the chance to have its on sphere overlap function called, in which case the

04:45.070 --> 04:50.710
projectile would be destroyed before it could go ahead and play the sound and spawn the system.

04:50.710 --> 04:54.700
So what we can do here is an on sphere overlap.

04:54.700 --> 05:02.110
If we overlap before being destroyed on the client, what we can do is we can set some kind of boolean

05:02.110 --> 05:04.900
and say we've already taken care of these effects.

05:04.900 --> 05:11.740
And then once the act of destruction has replicated, we can check that boolean and see if we've already

05:11.740 --> 05:12.670
played those effects.

05:12.670 --> 05:14.390
And if not, we can play them.

05:14.570 --> 05:15.950
So here's what I'd like to do.

05:15.950 --> 05:17.990
I'd like to have a Boolean.

05:18.200 --> 05:21.230
It can be private, a bool called Be Hit.

05:21.260 --> 05:25.910
We'll set it to false and in or a projectile if we don't have authority.

05:25.910 --> 05:32.630
So we'll have an else case here we're going to set be hit equal to true and then we can override a function

05:32.630 --> 05:36.200
that gets called when our actor is destroyed.

05:36.200 --> 05:38.210
That's a public function.

05:38.210 --> 05:44.900
We can say virtual void destroyed and we can override destroyed.

05:44.900 --> 05:50.420
So before calling super destroyed, we can check if B hit.

05:52.070 --> 05:56.690
And we want to play the sound and spawn the system.

05:56.690 --> 06:04.820
If destroyed is called before on sphere overlap, in which case be hit is going to be false.

06:04.820 --> 06:07.490
So we're going to say if not be hit.

06:07.850 --> 06:12.020
But also this only really pertains to clients.

06:12.020 --> 06:18.170
So we're going to say if not be hit and not has authority.

06:19.080 --> 06:23.570
And in that case, we'll go ahead and play the sound and spawn the system.

06:23.580 --> 06:26.820
So on sphere overlap will happen on the server.

06:26.820 --> 06:31.160
We'll get those cosmetic effects and then we'll check for authority.

06:31.170 --> 06:34.890
We'll have it and we'll call destroy and that's it.

06:35.160 --> 06:38.550
And on the client, one of two things will happen.

06:38.550 --> 06:44.880
First, either on sphere overlap will happen first or the act of destruction will replicate down to

06:44.880 --> 06:45.720
the client.

06:45.720 --> 06:47.460
And that will happen first.

06:47.580 --> 06:53.360
Now let's just say that destruction replicates before the clients on sphere overlap.

06:53.370 --> 06:59.670
Well, in that case, be hit will be false and has authority will be false.

06:59.670 --> 07:06.420
So we'll play those effects and the actor will be destroyed and on sphere overlap will never be called.

07:06.780 --> 07:13.350
But in the case that on sphere overlap is called before destruction replicates, then we get those effects.

07:13.380 --> 07:15.660
We check for authority and fail.

07:15.660 --> 07:23.350
We get into the if statement and say be hit equals true, so we'll get those effects regardless.

07:23.380 --> 07:28.480
Now on sphere overlap should not be called after destroyed has been called.

07:29.030 --> 07:36.200
So now we should be able to see and hear some effects when our projectile hits something and we see

07:36.200 --> 07:41.550
that it's set to overlap world, dynamic, world static and pawn.

07:41.570 --> 07:47.840
So why don't we go ahead and compile and launch and see if we can find some assets to use?

07:50.210 --> 07:53.090
Okay, so let's find our projectile.

07:53.120 --> 07:55.280
Blueprint in blueprints.

07:55.700 --> 07:58.400
And I believe this is an ability system.

07:58.430 --> 07:59.780
Gameplay abilities.

07:59.780 --> 08:01.520
Fire firebolt.

08:01.520 --> 08:03.620
And it's our firebolt.

08:03.650 --> 08:05.000
Here's our projectile.

08:05.300 --> 08:08.960
Now we have a couple of assets to set here.

08:09.110 --> 08:13.760
We have impact, effect and impact sound.

08:14.270 --> 08:16.610
Now let's look at our assets folder.

08:18.470 --> 08:21.020
We'll go to Effects projectiles.

08:21.020 --> 08:23.430
And here we have a fire explosion.

08:23.450 --> 08:24.500
There's two of them.

08:24.710 --> 08:26.450
Let's check out one of them.

08:26.810 --> 08:28.220
Here's what it looks like.

08:29.200 --> 08:31.300
And we have a second one.

08:31.920 --> 08:33.540
Here's what that looks like.

08:34.880 --> 08:36.470
So they both look pretty good.

08:36.770 --> 08:38.180
So we can choose one.

08:38.180 --> 08:40.520
I'm going to browse to one of them.

08:40.520 --> 08:42.590
I'll actually select the second one.

08:42.590 --> 08:45.770
And here for impact effect, I'll set it there.

08:46.580 --> 08:48.020
Now for the impact sound.

08:48.020 --> 08:49.610
Let's see what sounds we have in assets.

08:49.610 --> 08:54.950
We'll go to assets, sounds, abilities, firebolt.

08:54.950 --> 08:57.500
And we have some sound effects.

08:57.500 --> 08:59.150
Here's one for launching.

09:00.320 --> 09:04.880
Here's SFX Firebolt impact and then we have a hiss.

09:06.030 --> 09:10.350
And that's a looping sound that we can attach to our projectile.

09:10.380 --> 09:12.380
But for now, let's use our impact sound.

09:12.390 --> 09:13.680
I'm going to select it.

09:14.400 --> 09:15.750
And set it there.

09:16.140 --> 09:18.510
And now we can just test this out.

09:19.330 --> 09:20.710
So I'm going to press play.

09:21.830 --> 09:23.240
I'm going to click on an enemy.

09:26.070 --> 09:31.980
And it looks like we hit something on the way and we hit something and the sound effect has an attenuation

09:31.980 --> 09:33.030
set for it as well.

09:33.030 --> 09:37.200
So it's going to sound quieter the farther away it is.

09:37.500 --> 09:39.660
Now, I think we hit a potion.

09:39.900 --> 09:45.870
Yeah, I think we hit a potion and that actually consumed the potion, funnily enough.

09:46.140 --> 09:52.440
So we'll have to configure our collision settings exactly how we want, but at least we see that we've

09:52.440 --> 09:57.810
got our effect for when our fireball hits something and it looks like it's working.

09:58.050 --> 09:58.920
Excellent.

09:58.950 --> 10:05.160
Now, we saw that we had another firebolt sound called SFX Firebolt.

10:05.700 --> 10:08.820
We can use that in our attack animation.

10:09.000 --> 10:14.100
So what I'd like to do is go to aura animations abilities.

10:14.100 --> 10:19.740
I'm going to go into my cast firebolt montage and play a sound in here.

10:19.830 --> 10:30.430
So I'm going to go ahead and add a new notify track called Sound and right here I'm going to add a notify

10:30.460 --> 10:31.630
play sound.

10:32.110 --> 10:36.790
And select SFX Firebolt.

10:39.020 --> 10:43.130
Like so and saving all.

10:43.460 --> 10:44.870
I'm going to try it out.

10:46.860 --> 10:48.420
First on the client.

10:51.900 --> 10:52.800
Nice.

10:52.800 --> 10:54.840
And on the server.

10:55.380 --> 10:57.660
Nice Looking good.

10:57.960 --> 11:05.910
And the last thing to do is to spawn a sound effect and attach it and make sure it's looping.

11:06.060 --> 11:10.860
We can attach it to the firebolt itself so we can have a looping sound.

11:11.190 --> 11:14.220
And that's going to be your quest.

11:14.550 --> 11:20.010
So for this quest, you're going to add a looping sound for your projectile.

11:20.280 --> 11:26.940
So add the looping sound, take care of what you need to take care of in C plus plus and in blueprint,

11:26.940 --> 11:28.860
choose a looping sound effect.

11:28.860 --> 11:33.990
And when you're done, play test and make sure that it looks and sounds great.

11:34.110 --> 11:37.500
So pause the video and conquer this quest now.

11:41.030 --> 11:41.630
All right.

11:41.630 --> 11:43.340
I'm going to close the editor.

11:44.350 --> 11:46.540
And go back to Aura Projectile.

11:46.840 --> 11:49.510
Now we're going to want a looping sound.

11:49.540 --> 11:54.040
So I'm simply going to copy impact sound and paste another one.

11:54.220 --> 11:56.800
And this will be our looping sound.

11:57.340 --> 12:00.600
Now we want to spawn a sound and attach it.

12:00.610 --> 12:07.810
So if we go back to Aura Projectile, we can go into Begin play and spawn a sound here with you.

12:07.810 --> 12:14.440
Gameplay Static's spawn sound, but we can spawn one attached.

12:14.440 --> 12:18.910
So this allows us to spawn the sound and attach it.

12:18.910 --> 12:25.600
And this function returns a sound component that we can store so that we can stop the sound later.

12:25.750 --> 12:28.360
So first we need to pass in the sound.

12:28.360 --> 12:30.280
That's going to be our looping sound.

12:30.460 --> 12:33.950
Next, we need a scene component to attach to.

12:33.970 --> 12:38.530
I'm just going to call get root component so we can attach it to the root.

12:38.560 --> 12:41.870
Now it takes a number of optional parameters.

12:41.890 --> 12:48.310
We can literally leave them all out and spawn sound attached will spawn the sound.

12:48.340 --> 12:51.140
Now it returns a new audio component.

12:51.160 --> 12:57.580
I'd like to store that in a variable so we can stop the sound in on sphere overlap.

12:57.580 --> 13:02.410
So let's get a u audio component pointer variable.

13:02.410 --> 13:14.560
So this will be a T object pointer of type u audio component called looping sound component and this

13:14.560 --> 13:16.810
will get its own U property.

13:17.020 --> 13:18.130
There we go.

13:18.280 --> 13:26.320
So spawn sound attached and similar functions in gameplay statics spawn a sound and return a component.

13:26.320 --> 13:32.410
So this is one of those few cases where we're creating a component that doesn't live on an actor.

13:32.440 --> 13:36.450
Usually components live on actors, but this one does not.

13:36.460 --> 13:39.580
It's just a component floating around in the world.

13:39.580 --> 13:45.050
But we can store that in our audio component, which we called looping sound component.

13:45.050 --> 13:46.520
So we'll store that.

13:46.520 --> 13:55.360
And then in on sphere overlap as we're playing the sound for impact and spawning the system for impact,

13:55.370 --> 13:57.580
we'll go ahead and stop the sound.

13:57.590 --> 14:08.330
So looping sound component we're going to call stop and when destroyed, we'll call stop here as well.

14:08.510 --> 14:09.860
Let's test this out.

14:12.480 --> 14:14.340
So let's open our actor.

14:19.260 --> 14:21.720
And we'll search for looping.

14:21.750 --> 14:23.570
Here's our looping sound.

14:23.580 --> 14:28.170
We'll set it to SFX Firebolt Hiss.

14:29.290 --> 14:31.330
And let's see how this works.

14:31.450 --> 14:33.760
We'll try first on the client.

14:37.520 --> 14:39.530
And I hit something right away.

14:40.520 --> 14:42.230
I'll try on the server now.

14:44.330 --> 14:46.520
So it looks like the sound is stopping.

14:46.520 --> 14:49.160
Let's make sure that it's actually playing though.

14:50.660 --> 14:52.640
Oh, yeah, we can definitely hear that.

14:53.870 --> 14:55.370
That sounds great.

14:55.370 --> 15:00.290
And that fireball just went off into the distance and it's never going to die.

15:00.560 --> 15:05.480
So we should probably set the life span on our actor.

15:05.810 --> 15:11.600
So before we wrap up, I'm just going to go ahead and set a lifespan.

15:11.690 --> 15:17.840
I'll make this a uproperty variable, a float called Lifespan.

15:19.390 --> 15:21.100
I'll set it to 15 seconds.

15:21.100 --> 15:26.290
I think that's plenty and make it edit anywhere.

15:26.290 --> 15:28.540
I'll make it edit defaults only actually.

15:29.020 --> 15:36.040
And as soon as we spawn our projectile, I'm going to set its lifespan right here and begin play.

15:37.030 --> 15:47.950
We'll call set lifespan to lifespan so that way our projectiles will only last for 15 seconds maximum

15:47.950 --> 15:50.320
if they don't get destroyed before that.

15:51.060 --> 15:51.500
Okay.

15:51.510 --> 15:52.470
Great job.

15:52.500 --> 15:54.360
Things are looking awesome.

15:54.360 --> 15:55.950
They're sounding great.

15:55.980 --> 16:00.630
We're now just about ready to start causing damage with our projectiles.

16:01.260 --> 16:03.370
So we'll do that in the videos to come.

16:03.390 --> 16:05.490
Great job and I'll see you soon.
