Hey welcome back everyone.
Mark here and this is the exciting video because now we get to add a gun and I'm super excited.
So first things first is let's get the gun.
So what I want to do is open up my content here right click and go to shore.
Show an explorer.
OK.
And what I'm going to do is grab the weapon you grab it as well too from the downloaded files grab the
weapon copy it.
We're going to paste it into our project.
Like so
and alternatively if you get this weapon and for some reason your materials are broken.
If you go into your weapon here and you look at the mesh and you drag it into your scene and if you
don't see a gun that's orange and gray because something's broken it means that the import just didn't
work correctly sometimes when you export assets.
So other people can import them.
Things can break materials can break.
And if that happened you can either just roll with the video as is or what you can do is you can go
create a new project the file new project and select the first person game and then go into their own
gun mesh that they have that go into there.
This is what I did.
This is the same exact weapon.
I just changed the materials on it.
You can go into their weapon like so there FP weapon you can right click it and go to migrate and then
migrate it into the content folder of the project that we're working on here.
That's another way of doing it.
And that always seems to work.
So what I've done is I've just styled the gun and made it cooler.
I think it looks cooler anyway kind of has like a half life kind of feel to it.
And so this looks good to me having to delete it out of the out of the world outline are here and what
do we want to do.
Well we want to get that gun positioned properly and then we want to spawn it at runtime.
So let's do that now.
What we're going to do is we're gonna go into the Adam's starter pack that was given to us AR that we
imported and I'm going to look for the idol animation which I seem to struggle to find sometimes her
idol rival hip I'm going to double click it when I drag this up here in the tab and what I want to do
is I want to position the gun about where it's supposed to be.
So what I'm going to do is I'm going to go find the right hand go find the right hand here in THE SKELETON
TREE.
SO clavicle are that would be the right clavicle and then the hand.
Ah okay.
Close right here.
So minimize those for a moment.
So with hand are selected for the right hand.
I'm gonna right click WHAT WE'RE GONNA DO IS WE'RE GONNA ADD A socket now a socket is like a representation
of something that you're going to put there.
So it's not actually manipulating the mesh in any way but we're kind of putting a reference there that
we can access later and blueprint saying hey this is where we want to put the gun somebody double click
this I'm going to call this gun socket like so and then I'm going to right click it and I'm going to
go to ad preview asset and select the gun.
Now what's really cool about this is it's going to allow us to line it up about where we think it should
be here.
When the game starts so let's go ahead and rotate it get it look in nice and rotated and we we're just
going to make this kind of look nice we're not going to go crazy perfect on it it's going to move it
around until we get where we want it to be.
Let me pause this I don't animation here for a moment and then I want to just move this little guy around
until he's about where I think it should be which would be holding the you know the orange grip underneath
there and and he's kind of bleeding through here but it doesn't have to be perfect.
The most important thing is that it kind of looks right from our camera perspective.
And so if this is our camera
we're going to see it kind of like this and he's gonna shoot from the hip which is fine now I'm just
looking around here.
You know we could probably play with it a little bit more.
That backhand is kind of.
That's kind of where the you know the trigger is within that right hand is kind of over there.
It's not gonna be perfect but that's OK and I'm just looking at how it looks.
And you know what the gun's moving with the body.
And the reason why it's moving is because we attach it to the sockets.
That looks really nice.
So I'm going to save this again.
We haven't actually added this gun to the skeleton.
This is just a reference with a preview.
OK.
We have we have to add this later on we get anything here that we want it.
And so I'm going to close out of this just remember that name and gun socket.
And now what we want to do is we want to create a blueprint for a gun.
Why might you ask.
Can't we just take the gun and go in to our character player character why can't we just add a static
mesh for the gun right here and then line it up.
Well we could we could but we might run this and problems like it might not animate correctly with the
arms rather move with the arms because they're not attached to the socket.
Secondly what if we want to shoot projectiles.
How do we make sure it's at the tip of the gun OK.
We could add some more components in here and do often the character now a character class is going
to start getting really messy.
But then what about when we want it like pick up a new gun off the ground and swap them out.
Well now we have a real problem because we have a static mesh there so it doesn't make sense at all
to just add the static mesh the model there that it needs its own blueprint with its own functionality
in life.
So we're going to right click go to blueprint class.
Now we're just gonna choose the base class actor.
It's just going to be an actor in our world and we're going to call this weapon.
All right.
And I'm gonna double click to open the blueprint editor and inside of the weapon I'm gonna add a skeletal
mesh are our weapon actually does have a skeletal mesh and so we're gonna call this call it the gun
had a gun and then over on the right hand side for skeletal mesh.
I'm gonna select the gun like so and I'm going to compile and save and I think that's all we're gonna
do with this right now.
In the future we'll add some functionality to this.
So basically what we've done is created a blueprint something that can be dynamically instantiated at
runtime and reused over and over again and we might make.
We can always make a base class for all the guns that has like a reload count and things like that and
we could subclass and you know create like a pistol and things like that so using a blueprint is very
very useful here.
OK.
And so what we're gonna do now is on the player character we just want to spawn the gun.
We want to get the gun attaching to the character at runtime.
Again we're not attaching a static mesh to the character because we don't get the functionality.
So we have to do that here in blueprint.
And what I'm gonna do is make sure I don't have it already which I don't I'm going to add a new event
here called begin play event begin play when the game first starts.
I'm in this up here slightly.
And what we want to have happen is we want to spawn the weapon make sure we position it correctly and
that's it.
So let's go ahead and right click.
In fact it's sometimes better just a drag right off of this.
This the line here and we're gonna say spawn actor from class.
Okay.
And what does class mean if if you're new to programming.
Now this is like object oriented programming like it's it's underneath the hood of the blueprint we've
got a class something that represents what we're doing here.
And so we want to spawn our weapon.
So I'm typing in the word weapon and there you have it right there.
Now the first thing we need to do is Hey where do we want to where do we want to spawn this in the world.
Like where do we want to put it.
Well we want to put it on our character and then specifically in the socket.
So the first thing we want to do is just grab our character so grab the character mesh and drag them
in here in the scene or in the event graph.
And then what we're gonna do is we just want to get the meshes transform.
So we're going to say Get world transform we want to get we want to get his place in the world and then
we're gonna just plug that into the spawn transform like.
So now what we want to do is when it spawns is actor we want to save it somewhere.
So we're gonna drag off of the return value and say promote to variable and again if you are familiar
with programming this is very similar to like instantiating a class like creating an object in your
programming language and then storing it in a variable so you can access it later from other classes.
And we're gonna give this a name we're gonna call it weapon.
So now our weapon is in a variable and we can do things with it which is kind of cool.
I'm going to move all this up a little bit higher and then the last thing we want to do.
So we've spawned it in the world and we've even put it right next to the player but we actually haven't
put it on top of the player.
Does that make sense.
Yes we've gotten ready in the right position but we haven't actually attached it to the socket so it
always stays with the player.
So right now if we just did this and it was spawned in the player runs the gun's gonna be left behind.
So that's obviously not what we want.
This is a pretty simple thing to do.
We're gonna drag off of the weapon and we're gonna say attach to component bone where we want to attach
this weapon to a component.
So the target Okay that's gonna be the weapon.
What is the target meaning what.
What do we want to attach the component basically.
And then who's the parent.
Well where do you have the parent.
It's the mesh.
So basically the moment we do this.
Okay.
The object is first transform at the location of the parent or of the mesh.
And then now we're attaching it to it so that wherever the player goes the weapon is going to go with
it.
This of course is just unacceptable so mean a double click for a rerouting node and do it again over
here.
We just cannot have nasty little wires.
I mean terrible can't even click today.
Goodness.
Hey are you OK.
We're gonna apparently have an unreliable node here.
Oh boy were Arrigo okay little guy do your magic all right.
It's going to drag this down right there and move this up right here.
Okay.
So we've got the mesh as the parent.
That's what we're attaching to the weapon is the target.
And then what we want to do is something really cool.
Set the socket which was gun socket.
That's what we named it in the in the animation on the skeleton tree.
And it's going to know how to find this automatically for us.
It's just gonna find it and attach in that very particular spot.
Lastly this is gonna be very important if you don't change these you you'll you'll see why you're gonna
be in the wrong direction.
But what we want to do is snap to target snap to target and snap to target.
So basically we want to make sure that all the rotations in here are locked in.
Okay.
We don't want them rotating based on the world or other factors and things like that we want them locked
into our weapons rotational world which of course is attached to the parent.
So this looks good.
So when we start playing we're gonna spawn an actor of a weapon and then we're gonna put it in a variable
and then we're gonna attach it to the component in the sockets place to pick the place.
I'm going to highlight all of these here and let's call this spawn weapon and we will compile and save
and hopefully this all turns out okay.
Let's go ahead and save it here and I'm gonna click play and sure enough we've got a cool looking gun
here.
Woo kind of goes in his body here I might adjust that later on.
You know push it out a little bit more but you know what.
This is pretty cool.
I can imagine a laser coming out of here boom boom boom shooting.
And I think we might be a little too close to our player but that's okay for now.
He's looking really really cool and yeah by the way I did those material designs.
I mean of course Epic Games that all the hard work I just did some coloring and some shading and stuff
but I think it looks pretty cool.
So we're gonna call this video done and by the way you can also look at your weapon in here at any time
as well too by double clicking on it.
Well that's the weapon blooper I wanted to show you the weapon mash.
I mean you can go into your weapon FP weapon mesh and you can double click and look at this and it is
a time as well to create your own materials if you wanted to modify the gun and make it look the way
that you want to look and there's the material right there you can just double click it and change things
around.
So good stuff here.
Ladies and gentlemen making great progress.
We've got a guy with a gun a dummy with a gun and he's gonna go shoot some other dummies.
And that's it.
So I'll see you real soon.