﻿1
00:00:04,390 --> 00:00:05,440
‫Hello and welcome.

2
00:00:05,440 --> 00:00:10,870
‫In this lecture, we're going to be looking at spawning a muzzle flash so that when we hit the trigger,

3
00:00:11,350 --> 00:00:13,450
‫we get a particle effect.

4
00:00:13,450 --> 00:00:16,840
‫So let's dive in and see how we can do this from C++.

5
00:00:18,300 --> 00:00:18,450
‫Okay.

6
00:00:18,510 --> 00:00:22,860
‫So we want some particle effects to spawn from the muzzle of our gun.

7
00:00:22,980 --> 00:00:25,180
‫What's going to be the best way to do this?

8
00:00:25,200 --> 00:00:29,820
‫We kind of first of all, have a look at what particle effects we've got available here.

9
00:00:29,910 --> 00:00:31,880
‫I've taken the ones from the shooter game.

10
00:00:31,890 --> 00:00:35,650
‫Obviously, you can use any particle effects that you want.

11
00:00:35,670 --> 00:00:37,800
‫You can find them on the asset store.

12
00:00:37,830 --> 00:00:40,500
‫You can take them from example projects like I have.

13
00:00:40,590 --> 00:00:42,120
‫We want to go under the effects.

14
00:00:42,120 --> 00:00:48,330
‫So asset packs, shoot game effects and then look at particle systems, weapons, assault rifle.

15
00:00:48,330 --> 00:00:51,270
‫And I'm looking for the muzzle one at least initially.

16
00:00:51,270 --> 00:00:53,640
‫And we want this assault rifle.

17
00:00:55,080 --> 00:01:00,180
‫And you should be able to see it's going to take a little bit of time to get the shaders in here compiling.

18
00:01:00,180 --> 00:01:03,660
‫But this is what essentially the muzzle flash looks like.

19
00:01:03,660 --> 00:01:04,830
‫It looks like a muzzle flash.

20
00:01:04,830 --> 00:01:11,490
‫So that's what we're going to be using and we're going to try and spawn this in C++ when we have the

21
00:01:11,490 --> 00:01:12,270
‫trigger pulled.

22
00:01:12,270 --> 00:01:15,550
‫So let's go over into our gun.

23
00:01:15,570 --> 00:01:16,920
‫I'm going to go to the gun.

24
00:01:16,920 --> 00:01:23,280
‫CP And instead of this log message of having been shot, not particularly useful, we want to spawn

25
00:01:23,280 --> 00:01:24,840
‫a particle effect.

26
00:01:25,200 --> 00:01:28,980
‫And to do this, we're going to be using a function from the gameplay statics.

27
00:01:29,550 --> 00:01:33,240
‫So let's go over to the gameplay static start and have a little look in here.

28
00:01:33,240 --> 00:01:39,120
‫We want to spawn an emitter, they're calling it spawn an emitter.

29
00:01:39,120 --> 00:01:45,880
‫And you will see if we have a look at this that what it's taking in is a world context object.

30
00:01:45,900 --> 00:01:52,050
‫It's taking in a particle system, which is the emitter template, as they're calling it, the location,

31
00:01:52,050 --> 00:01:54,300
‫rotation, scale, blah, blah, blah, blah, blah.

32
00:01:54,420 --> 00:02:04,770
‫Or alternatively, I think you can make it attached so we can do a spawn emitter attached, and this

33
00:02:04,770 --> 00:02:11,190
‫is going to try and attach it to a component so we can see that this takes in a scene component to attach

34
00:02:11,190 --> 00:02:11,940
‫to.

35
00:02:11,970 --> 00:02:14,190
‫Now, in this case, I think this is what we want.

36
00:02:14,190 --> 00:02:16,860
‫It depends on the particle effect in question.

37
00:02:17,070 --> 00:02:23,070
‫But some particle effects are going to keep spawning particles for a duration of time.

38
00:02:23,070 --> 00:02:26,850
‫So you want those particles to keep coming out of the muzzle of the gun.

39
00:02:27,030 --> 00:02:30,660
‫As the gun moves, they might be creating some smoke, some stuff like that.

40
00:02:30,660 --> 00:02:35,520
‫If you move your gun while you're shooting, you want the particle effect to move with it.

41
00:02:35,880 --> 00:02:40,320
‫So that's what we're going to be using is this spawn emitter attached.

42
00:02:40,410 --> 00:02:48,150
‫And as it says here, it's going to take in the emitter template and the scene component that we need

43
00:02:48,150 --> 00:02:49,440
‫to attach to.

44
00:02:49,470 --> 00:02:51,700
‫So those are the things that we're mostly going to be needing.

45
00:02:51,720 --> 00:02:56,250
‫It also has this attach point name that's going to be a socket.

46
00:02:56,250 --> 00:03:02,490
‫So that's actually quite handy for us to know that we can attach it directly to the muzzle of our gun.

47
00:03:02,490 --> 00:03:06,360
‫We don't need any kind of offsets, so let's have a look at that.

48
00:03:06,360 --> 00:03:11,670
‫If I go and open up my BP rifle, we already know we've mentioned that this is a skeletal mesh.

49
00:03:11,670 --> 00:03:18,570
‫So I'm going to go and find that rifle in the content browser and open up the rifle mesh.

50
00:03:19,230 --> 00:03:24,930
‫And what you'll see over in the left, if you have the skeleton tree pane visible, then you're going

51
00:03:24,930 --> 00:03:30,840
‫to see that we've got this rifle route, we've got the rifle magazine, which presumably can be swapped

52
00:03:30,840 --> 00:03:33,450
‫out or something, but we don't particularly interested in that.

53
00:03:33,450 --> 00:03:35,850
‫And then there's this muzzle flash socket.

54
00:03:35,850 --> 00:03:40,260
‫So that's where we're going to spawn our muzzle flash.

55
00:03:40,260 --> 00:03:45,570
‫If it didn't have or your mesh doesn't have this, then you can go ahead and add one because we can

56
00:03:45,570 --> 00:03:48,960
‫always add sockets in the way we've seen in previous lectures.

57
00:03:49,260 --> 00:03:51,750
‫So let's have a go at spawning this.

58
00:03:51,750 --> 00:03:59,610
‫The first thing we're going to need is one of these particle system references, and the best way to

59
00:03:59,610 --> 00:04:07,140
‫do that again, the best way that I know how is to create a new property and do it in blueprint.

60
00:04:07,140 --> 00:04:12,420
‫There are other ways you can do it by named references, but I really don't like using named references.

61
00:04:12,420 --> 00:04:17,490
‫They break easily if you rename stuff, so much easier to do it in blueprint where all of that is handled

62
00:04:17,490 --> 00:04:18,210
‫for you.

63
00:04:18,360 --> 00:04:26,400
‫We're going to make this a you property edit defaults or actually this could be edit anywhere y because

64
00:04:26,400 --> 00:04:32,190
‫if we were to change this during gameplay which you might want to do, if you're trying to tweak things

65
00:04:32,190 --> 00:04:37,050
‫and say, oh, well, does this particle effect look better than this one, then this would actually

66
00:04:37,050 --> 00:04:37,320
‫work.

67
00:04:37,320 --> 00:04:40,800
‫The next time you shoot, a different particle effect would be created.

68
00:04:41,100 --> 00:04:43,390
‫And then the type of this needs to be a U.

69
00:04:43,410 --> 00:04:49,920
‫Particle system pointer, which we're going to call our muzzle flash like that.

70
00:04:50,100 --> 00:04:53,040
‫And that's what we're going to be setting up over in Blueprint.

71
00:04:53,040 --> 00:05:01,590
‫And let's go back in to our pull trigger method in the C++ and we want to call it that U gameplay statics

72
00:05:01,590 --> 00:05:02,610
‫function.

73
00:05:03,180 --> 00:05:11,970
‫So U gameplay statics notice it's not auto completing here because I need a hash include for this by

74
00:05:11,970 --> 00:05:15,930
‫hover over that gameplay static so you can see that it's under engine classes.

75
00:05:15,930 --> 00:05:17,550
‫Kismet gameplay static.

76
00:05:17,640 --> 00:05:24,900
‫So all we need to do is kismet gameplay static stage and we should have you game play statics to auto

77
00:05:24,900 --> 00:05:30,930
‫complete from and we want to spawn and this may or may not work because of the version that I'm in in

78
00:05:30,930 --> 00:05:31,350
‫unreal.

79
00:05:31,350 --> 00:05:38,220
‫We want to spawn the emitter attached and we want this muzzle flash right here.

80
00:05:39,430 --> 00:05:42,310
‫And we want to attach it to a scene component.

81
00:05:42,310 --> 00:05:48,520
‫In this case, we want to attach it to to our guns mesh and we want to attach it to the appropriate

82
00:05:48,520 --> 00:05:55,090
‫socket, which, again, I'll let you fill out is the if we go over to the gun, it is the muzzle flash

83
00:05:55,090 --> 00:05:55,450
‫socket.

84
00:05:55,450 --> 00:06:02,260
‫I'm going to copy it from there directly and just put a semicolon on the end of the line to top it off.

85
00:06:02,350 --> 00:06:03,910
‫So this should work.

86
00:06:03,910 --> 00:06:08,050
‫Let's go over and hit compile in the engine.

87
00:06:09,050 --> 00:06:15,520
‫And once that's finished compiling we can go over into our BP Underscore Rifle Open the full blueprint

88
00:06:15,530 --> 00:06:22,970
‫editor I just prefer to deal with that and look at our let's see if we go to the root.

89
00:06:23,000 --> 00:06:27,050
‫In fact, the actor itself or the class defaults go to the details pane.

90
00:06:27,050 --> 00:06:32,600
‫You can see we've got this muzzle flash property, the new one, and we need to find a particle effect

91
00:06:32,600 --> 00:06:33,050
‫in here.

92
00:06:33,050 --> 00:06:36,380
‫I'm going to look for the keyword muzzle.

93
00:06:36,380 --> 00:06:37,310
‫Let's see.

94
00:06:37,940 --> 00:06:40,490
‫Maybe muzzle was not the one we were looking for.

95
00:06:40,490 --> 00:06:42,120
‫It's assault rifle MF.

96
00:06:42,140 --> 00:06:43,100
‫I think so.

97
00:06:43,130 --> 00:06:44,030
‫Muzzle flash.

98
00:06:44,030 --> 00:06:45,410
‫Is that what it's standing for?

99
00:06:45,410 --> 00:06:47,960
‫So assault rifle.

100
00:06:48,530 --> 00:06:52,250
‫MF That's the one we want to compile and save that.

101
00:06:52,250 --> 00:07:00,410
‫And we'll go over into our sandbox and hit play and see if shooting indeed launches up our muzzle flash.

102
00:07:00,410 --> 00:07:03,680
‫And you can see that it is continuously shooting at the moment.

103
00:07:03,680 --> 00:07:07,790
‫So we do want it to just be a single muzzle flash.

104
00:07:09,030 --> 00:07:12,150
‫So I think I'll actually choose a different muzzle flash.

105
00:07:12,150 --> 00:07:17,880
‫I think I'll use the one from the Wraith asset pack, which we've got sniper and primary.

106
00:07:17,880 --> 00:07:22,860
‫I'm going to choose the primary just because I'm not wanting to create a rapid fire weapon.

107
00:07:22,860 --> 00:07:25,170
‫That's a slightly different way of doing things.

108
00:07:25,170 --> 00:07:30,120
‫It's not not massively different, just more of a kind of once you're holding, you start the emitter

109
00:07:30,120 --> 00:07:33,460
‫and once you are finished with it, you want to close it down.

110
00:07:33,480 --> 00:07:36,570
‫In that case, we just want to launch that emitter one time.

111
00:07:36,570 --> 00:07:43,740
‫So we're going to do ULP again and see if we there we go, now we shoot, we get a single flash of the

112
00:07:43,740 --> 00:07:46,320
‫muzzle and everything is hunky dory.

113
00:07:46,320 --> 00:07:52,170
‫It seems to be attached nicely to the end of the gun as well as I move around, wherever I move around,

114
00:07:52,170 --> 00:07:55,440
‫whichever way I face the muzzle flashes in the right direction.

115
00:07:55,440 --> 00:07:55,860
‫Cool.

116
00:07:55,860 --> 00:08:00,570
‫Well, this is really starting to look more like a shooter game with particle effects.

117
00:08:00,570 --> 00:08:06,990
‫So in the next lecture, we're going to look at the first steps of ray tracing, which will be actually

118
00:08:06,990 --> 00:08:12,240
‫to go and reach up to our character owner for some information.

119
00:08:12,240 --> 00:08:13,320
‫I will see you there.

