‫Hello and welcome.
‫In this lecture, we're going to be looking at spawning a muzzle flash so that when we hit the trigger,
‫we get a particle effect.
‫So let's dive in and see how we can do this from C++.
‫Okay.
‫So we want some particle effects to spawn from the muzzle of our gun.
‫What's going to be the best way to do this?
‫We kind of first of all, have a look at what particle effects we've got available here.
‫I've taken the ones from the shooter game.
‫Obviously, you can use any particle effects that you want.
‫You can find them on the asset store.
‫You can take them from example projects like I have.
‫We want to go under the effects.
‫So asset packs, shoot game effects and then look at particle systems, weapons, assault rifle.
‫And I'm looking for the muzzle one at least initially.
‫And we want this assault rifle.
‫And you should be able to see it's going to take a little bit of time to get the shaders in here compiling.
‫But this is what essentially the muzzle flash looks like.
‫It looks like a muzzle flash.
‫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
‫trigger pulled.
‫So let's go over into our gun.
‫I'm going to go to the gun.
‫CP And instead of this log message of having been shot, not particularly useful, we want to spawn
‫a particle effect.
‫And to do this, we're going to be using a function from the gameplay statics.
‫So let's go over to the gameplay static start and have a little look in here.
‫We want to spawn an emitter, they're calling it spawn an emitter.
‫And you will see if we have a look at this that what it's taking in is a world context object.
‫It's taking in a particle system, which is the emitter template, as they're calling it, the location,
‫rotation, scale, blah, blah, blah, blah, blah.
‫Or alternatively, I think you can make it attached so we can do a spawn emitter attached, and this
‫is going to try and attach it to a component so we can see that this takes in a scene component to attach
‫to.
‫Now, in this case, I think this is what we want.
‫It depends on the particle effect in question.
‫But some particle effects are going to keep spawning particles for a duration of time.
‫So you want those particles to keep coming out of the muzzle of the gun.
‫As the gun moves, they might be creating some smoke, some stuff like that.
‫If you move your gun while you're shooting, you want the particle effect to move with it.
‫So that's what we're going to be using is this spawn emitter attached.
‫And as it says here, it's going to take in the emitter template and the scene component that we need
‫to attach to.
‫So those are the things that we're mostly going to be needing.
‫It also has this attach point name that's going to be a socket.
‫So that's actually quite handy for us to know that we can attach it directly to the muzzle of our gun.
‫We don't need any kind of offsets, so let's have a look at that.
‫If I go and open up my BP rifle, we already know we've mentioned that this is a skeletal mesh.
‫So I'm going to go and find that rifle in the content browser and open up the rifle mesh.
‫And what you'll see over in the left, if you have the skeleton tree pane visible, then you're going
‫to see that we've got this rifle route, we've got the rifle magazine, which presumably can be swapped
‫out or something, but we don't particularly interested in that.
‫And then there's this muzzle flash socket.
‫So that's where we're going to spawn our muzzle flash.
‫If it didn't have or your mesh doesn't have this, then you can go ahead and add one because we can
‫always add sockets in the way we've seen in previous lectures.
‫So let's have a go at spawning this.
‫The first thing we're going to need is one of these particle system references, and the best way to
‫do that again, the best way that I know how is to create a new property and do it in blueprint.
‫There are other ways you can do it by named references, but I really don't like using named references.
‫They break easily if you rename stuff, so much easier to do it in blueprint where all of that is handled
‫for you.
‫We're going to make this a you property edit defaults or actually this could be edit anywhere y because
‫if we were to change this during gameplay which you might want to do, if you're trying to tweak things
‫and say, oh, well, does this particle effect look better than this one, then this would actually
‫work.
‫The next time you shoot, a different particle effect would be created.
‫And then the type of this needs to be a U.
‫Particle system pointer, which we're going to call our muzzle flash like that.
‫And that's what we're going to be setting up over in Blueprint.
‫And let's go back in to our pull trigger method in the C++ and we want to call it that U gameplay statics
‫function.
‫So U gameplay statics notice it's not auto completing here because I need a hash include for this by
‫hover over that gameplay static so you can see that it's under engine classes.
‫Kismet gameplay static.
‫So all we need to do is kismet gameplay static stage and we should have you game play statics to auto
‫complete from and we want to spawn and this may or may not work because of the version that I'm in in
‫unreal.
‫We want to spawn the emitter attached and we want this muzzle flash right here.
‫And we want to attach it to a scene component.
‫In this case, we want to attach it to to our guns mesh and we want to attach it to the appropriate
‫socket, which, again, I'll let you fill out is the if we go over to the gun, it is the muzzle flash
‫socket.
‫I'm going to copy it from there directly and just put a semicolon on the end of the line to top it off.
‫So this should work.
‫Let's go over and hit compile in the engine.
‫And once that's finished compiling we can go over into our BP Underscore Rifle Open the full blueprint
‫editor I just prefer to deal with that and look at our let's see if we go to the root.
‫In fact, the actor itself or the class defaults go to the details pane.
‫You can see we've got this muzzle flash property, the new one, and we need to find a particle effect
‫in here.
‫I'm going to look for the keyword muzzle.
‫Let's see.
‫Maybe muzzle was not the one we were looking for.
‫It's assault rifle MF.
‫I think so.
‫Muzzle flash.
‫Is that what it's standing for?
‫So assault rifle.
‫MF That's the one we want to compile and save that.
‫And we'll go over into our sandbox and hit play and see if shooting indeed launches up our muzzle flash.
‫And you can see that it is continuously shooting at the moment.
‫So we do want it to just be a single muzzle flash.
‫So I think I'll actually choose a different muzzle flash.
‫I think I'll use the one from the Wraith asset pack, which we've got sniper and primary.
‫I'm going to choose the primary just because I'm not wanting to create a rapid fire weapon.
‫That's a slightly different way of doing things.
‫It's not not massively different, just more of a kind of once you're holding, you start the emitter
‫and once you are finished with it, you want to close it down.
‫In that case, we just want to launch that emitter one time.
‫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
‫muzzle and everything is hunky dory.
‫It seems to be attached nicely to the end of the gun as well as I move around, wherever I move around,
‫whichever way I face the muzzle flashes in the right direction.
‫Cool.
‫Well, this is really starting to look more like a shooter game with particle effects.
‫So in the next lecture, we're going to look at the first steps of ray tracing, which will be actually
‫to go and reach up to our character owner for some information.
‫I will see you there.