Now if we have our inventory we can start adding new weapons!
- Player can choose which weapon he want to play, (for now it will be placeholder UMG we did in inventory tutorial)
- Player can change weapon during gameplay with animation, (by keyboard now)
- Weapons will attach correctly,
- Hands will update idle animation to correctly hold the weapon,
We won’t be doing shooting / reloading in this post. Let’s focus on basics first.
This Tutorial has been created using Unreal Engine 4.8.2. Make sure you are working on the same version of the engine.
For this post I will use assets from Unreal Marketplace. I’ve chosen Military Weapons Silver.
New Enum: WeaponType
Create new Enum named WeaponType and add: Pistol, Rifle and Shotgun to it. You should know how to add Enums from reading Adding Inputs Tutorial.
BP_BaseWeapon
First we need to create base class for all of the weapons. Each weapon will extend from this class. Thanks to that we will be able to do some functions on them like Fire, Equip or getting variables like Ammo without knowing the exact weapon. This will be something like object-oriented programming.
Create new Blueprint extending from Actor and name it BP_BaseWeapon. Now inside:
- Create scene component as a root. This is something that I’m always doing when creating new blueprint,
- Create Skeletal Mesh Component and name it WeaponMesh,
- New variable: IndexInBackpack (int) which should be Editable and Exposed On Spawn,
We will be passing this from Backpack_Weapons in ShooterGameInstance, - New variable: AttachSocketName_FPP (name) default value: WeaponPoint
- New variable: AttachSocketName_TPP (name) default value: WeaponPoint
Those will be used to attach the weapon to FPP or TPP meshes. - New variable: WeaponType (enum WeaponType)
This will hold information for animation blueprint. Hands need to update animations for different weapon types.
For now it’s it. Later this blueprint will have variables like CurrentAmmo, MaxAmmo etc.
Updating WeaponBackpackItem structure.
Before we go further we need to update WeaponBackpackItem structure we had created earlier. WeaponToSpawn shouldn’t be Actor. It should be Class reference to BP_BaseWeapon. We will be using SpawnActorFromClass node later and we need reference to the class not to the actor.

USEFUL TIP: If you change structure variable name or type everything connected to it in blueprints will be disconnected! You need to double-check if everything is connected after changing something in Structures.
BP_Weapon_Pistol
Create new blueprint based on BP_BaseWeapon. Name it BP_Weapon_Pistol.
- In Components tab select WeaponMesh and chose Pistols_A skeletal mesh from Military Weapons Silver,
- Now you won’t see inherited variables from BP_BaseWeapon. To see them you need to click on small eye ;)

- After that you will be able to see variables created in BP_BaseWeapon and you can overwrite them!
- WeaponType should be Pistol,
- AttachSocketName_FPP should be S_PistolSocket
That’s all here, let’s create another weapon.
BP_Weapon_AssaultRifle
Again create new blueprint based on BP_BaseWeapon. Name it BP_Weapon_AssaultRifle.
- WeaponMesh should be Assault_Rifle_A,
- WeaponType should be Rifle,
- AttachSocketName_FPP should be S_AssaultRifle,
BP_Weapon_Shotgun
The same thing as above. WeaponType should be Shotgun, AttachSocketName_FPP should be S_Shotgun and WeaponMesh Shotgun_A.
That’s it. We have three weapons now!
Sockets
Open Hero_FPP_Skeleton.
On the left side you are seeing bones from skeleton. You can create sockets connected to bone. It can have relative location and rotation. We will use sockets to attach our weapons. This documentation from Epic is ideal place to learn about creating sockets and previewing meshes. I won’t be posting about how to create sockets – please read documentation.
Create these sockets from b_RightWeapon bone:
- S_Shotgun:
– Relative Location: (X=0.299006,Y=1.298091,Z=8.979076)
– Relative Rotation: (Pitch=85.000000,Yaw=90.000000,Roll=0.000000)
– Relative Scale: (X=1.200000,Y=1.200000,Z=1.200000) - S_AssaultRifle:
– Relative Location: (X=0.299006,Y=0.528186,Z=9.127792)
– Relative Rotation: (Pitch=85.000000,Yaw=90.000000,Roll=0.000000)
– Default Relative Scale 1,1,1 - S_PistolSocket:
– Relative Location: (X=0.714007,Y=1.284835,Z=11.106700)
– Relative Rotation: (Pitch=85.000000,Yaw=90.000000,Roll=0.000000)
– Relative Scale: (X=1.100000,Y=1.100000,Z=1.100000)
If you are previewing your meshes in sockets don’t be afraid that they won’t fit exactly to hands. We will be using AnimationBlueprint to fix that.
AnimationBlueprint
Animation blueprints controls how skeletal mesh will animate. It can take data from owner (in our example it will be GameplayCharacter) and use it to drive animation. Please read Epic’s documentation before moving forward.
Open HeroFPP_AnimatoinBlueprint and create new variables:
- BaseRotation – rotator default value: (Pitch=0.000000,Yaw=0.000000,Roll=-6.681010)
- PullDownPercentage – float, default 0
- CurrentWeaponType – WeaponType Enum,
We will be assigning those variables in Event Graph.
Now go to Animation Graph. Create something like this:
- Its taking FPP_LauncherAim animation,
- Then it’s connecting it to slot Normal, slots are mostly used for playing Montage Animations. If montage will be played it will go here to this slot. Please watch this tutorial form Epic. If you have time you should watch the full playlist. Montages documentation can be found here.
- Then it’s adding rotation to RightHand bone using BaseRotation variable, (without that our gun will be pointing up)
- After that it’s modifying b_Spline1 bone using Alpha (from 0 to 1) – it’s used to control equipping animation,
- Then it’s caching the pose to new cache called BasePose so we can use it later.
Now we need to blend pose by Enum – by our WeaponType.
You will be able to fill all of the TransformBone blocks but there is a new block called TwoBoneIK.
It should look like this:
Basically what it’s doing it’s taking b_LeftForeArm and trying to change bones location to focus on b_RightHand. If you select this node in Event Graph you will be able to change the location!

I’m using it to change left hand location to hold the weapon. TwoBoneIK is powerful and you should learn it!
Here you can find the whole animation blueprint.
That’s all in Animation Blueprint!
Preparing GameplayCharacter
Gameplay Character will be responsible for spawning weapons, attaching them to slots and changing them. Open GameplayCharacter and add some variables:
- WeaponSlot_1 (BP_BaseWeapon)
- WeaponSlot_2 (as above)
- WeaponSlot_3 (as above)
Here we will store references to weapons that we have chosen in Inventory before gameplay, - CurrentWeapon (BP_BaseWeapon)
This will hold current weapon reference so we can check which weapon player is holding, - isReloading (bool)
This will tell us if hands are doing reloading animation, - isChangingWeapon (bool)
We need to know if we are currently changing weapon, - WeaponPullDownPercent (float – default 0)
This will be used for put weapon down and up as a changing weapon animation. We don’t have any change weapon animation so we need to create one,
After variables let’s move to functions.
- GetShooterGameInstance – function like in other classes we have created, pure function which will return ShooterGameInstance,
- SpawnWeaponsAndAssignToSlots
This is important function. It will spawn meshes and plug them to WeaponSlot_X

- ShowWeapon – input “BP_BaseWeapon” named “WeaponToShow”
This is helper function to hide and show weapons in slots.

Those are all functions for now. We need to create one Custom Event in Event Graph because we will use Timeline to drive equip animation.
Create new custom event “Equip Weapon” with one input “BP_BaseWeapon” named “Which Weapon”

We are using Timeline. If you don’t know what’s Timeline please read Epic documentation.
Our timeline is driving float variable and a event.

Basically it will tell AnimationBlueprint to rotate hands down and up. When hands are down we are firing event to show the weapon we are equipping.
The last thing in Event Graph is to create key bindings for 1,2,3 and fire EquipWeapon event.

That’s all in GameplayCharacter!
Now if you want to test this out just add a button to UI_Debug_WeaponSelection like this one:
Take your time to learn animation blueprints and object oriented blueprinting.
Creating ShooterTutorial takes a lot of my free time.
If you want you can help me out! I will use your donation to buy better assets packs and you will be added to Credits /Backers page as well.Implementing game is taking time but writing about this is taking much more effort!










Pingback: Weapons – shooting and reloading functionalities | Shooter Game Tutorial
Pingback: Creating a Shotgun | Shooter Game Tutorial
Pingback: Creating an Assault Rifle | Shooter Game Tutorial
Hi
Thanks for your great tutorial.
I have done all parts you explained in this tutorial but when i play the game and choose weapons from inventory (like your gif on top of this page) , my weapons don’t appear .And button 1 , 2 and 3 don’t do anything.(I use UE 4.7.6 )
what should i do ?Is there anything that i should do ?
LikeLike
“The last thing in Event Graph is to create key bindings for 1,2,3 and fire EquipWeapon event.” – this need to be done in GameplayCharacter.
Make sure you have added this “Now if you want to test this out just add a button to UI_Debug_WeaponSelection like this one:” to your button in UMG.
It’s hard to say why it isn’t working for you – if you can send me your project on mail: shootertutorial@gmail.com and I will be able to take closer look.
LikeLike
Hi
I sent an email with subject “My Project”.
I think the problem is i have not used IndexInBackpack variable but i don’t how to use it and it’s not in this tutorial(you created it in this tutorial but you didn’t use it anywhere).
Thanks for helping
LikeLike
Im having this exact same issue.
LikeLike
Thanks! Will open your project Tomorrow, and let you know! Did you read previous tutorial about inventory? http://shootertutorial.com/2015/06/06/how-to-create-inventory/ Equipping won’t work without inventory.
LikeLike
Yes i did . I also used your blueprint folder and everything was ok but in this tutorial the only problem is when i choose textures in inventory(like you did in gif)for my weapons it doesn’t do anything and everything is fine like selecting and deselecting.
Thank you
LikeLike
Im having an issue where in GameplayerCharacter > SpawnWeaponsAdnAssignToSlots when trying to spawn the actor for each weapon slot. In the picture you provided the SpawnActor node has an Index in Backback input integer, but I have no idea where that came from because it is not included in my project, and it wasnt created anywhere else. Here is a picture.
LikeLike
It’s an issue with Editor – will post that in Answer Hub. What you need to do is to create node Spawn Actor from Class and select BaseWeapon as a class. Then you should see Index In Backpack int (if you had selected “expose on spawn”) and you just need to connect Weapon To Spawn to Class. It will work. Editor doesn’t see currently which class you are extending if you are moving from wire.
I will post here screenshots step by step how to do that, but I’m out of my computer now.
LikeLike
Thanks I got it working, but Its still not showing the weapons when switching slots.
LikeLike
I got the same problem with switching weapons. Could you say what the problem?
LikeLike
Hi it’s hard to say – it’s working for me. You would need to send me your whole project to shootertutorial@gmail.com and I will be able to check.
In the meantime here you can downloads my blueprints folder: https://www.dropbox.com/s/6oi4gx9n6uumjcu/Blueprints.rar?dl=0 check if you have everything exactly like I have.
LikeLike
I sent you project. Thanks for your help!
LikeLike
I found the problem. The problem is in editor itself and you did’nt mentioned about assigning the BP_Weapon_Pistol, Rifle and Shotgun in Backpack array in ShooterGameInstance)))
Thanks anyway for your reply!)
LikeLike
First time if you want to assign the BP_Weapon_Pistol, editor doesn’t see it. For it you should change default “Current weapon type” in “HeroFPP_Animation” one by one to make sure that editor see it. I don’t know why but by doing so it worked. I hope it will help to someone with the same problem
LikeLike
can u please explain, detailed if u can, how did u solve that ?
LikeLike
Hi,
If you have the time, could make an v2.0 weapons equipping without inventory ? (just have to press a key to get the weapon) :) ?
LikeLike
I’m having issue with the weapons, they all spawn : http://imgur.com/DZvQSZT
LikeLike
can you please put a link to download your project ?
LikeLike
i’ve followed all the tutorials but i cant figure out why weapons dont show up, may i send you my project ? can u help me ? thanks for the great work, keep it up man, u are awesome !
LikeLike
Hello,
Every error reply to current weapon variable, could you help me ? http://prntscr.com/7y711f
LikeLike
Hey everybody! I’m so glad, i finally did it.
Did the Tutorial yesterday and it did not work. After that i checked every step three times, downloaded the BP Folder and went more or less mad :)
But everything you need to succed is in the tutorial!
When you are going to do the step: “Updating WeaponBackpackItem structure”, there is a “USEFUL TIP”. Well it’s not really it Tip, it’s a MUST DO!
In your ShooterGameInstance is the Function “SetBackpackItemseleted”, there is one connection destroyed when you change WeaponBackpackItem to structure. It’s between “BreakWeaponBackpackItem and “Make WeaponBackpackIteam” – the purple guy!
remake this and everything will work totally fine!
cu in the next Tutorial:)
LikeLike
Hello,
i have already do this but my error stay, could help me ?
This is that error : http://prntscr.com/7y711f
Thanks !
LikeLike
Are you assigning current weapon in GameplayCharacter?
LikeLike
Yes, in the equip weapon just after “Show weapon” function.
LikeLike
Before I ask my question I just wanted to say thank you for this tutorial, it’s been really helpful for getting started in UE4.
My question is that (like another user) when I start my game I don’t see my guns and my 1-3 keys don’t do anything. I used a different arm rig and weapon models (but I made sure to adjust everything correctly), could this be the issue?
LikeLike
I wanted to say I fixed my problem. I forgot to add the weapons in Backpack Weapons.
LikeLike
Good tutorial! When i press “I” for the inventory, all works, selecting guns, changing with 1,2,3… but when i press it again and deselect from the slots, the gun mesh dosnt disappear, can you help me? thank you!
LikeLike
First of all thanks for taking the time to make these tutorials, secondly if you are going to use paid assets next time you may want to mention that in the overview first so people don’t waste their time following a tutorial they cant finish.
LikeLike
It’s entirely possible import weapons yourself. I got a few models from GameBanana’s Dev Hub and created my own animations. From there you can add the sound/effects in yourself.
LikeLike
I found you get much better results using the rifle idle animation for the base pose and rotating (no translation) the left shoulder bone. Using a Two Bone IK on the left forearm makes the left hand clearly lose sync from the gun when the idle animation is running.
LikeLike
That’s the spirit! I really suggest to just take your time and play around with UE4. Create your content don’t copy everything from ShooterTutorial – this is only inspiration! Good luck!
LikeLike
Pingback: Enemy: “Marine” | Shooter Game Tutorial
As other people said, this is straightforward. If you find problems, try to advance to the next section of this tutorial, and come later for the past one.
If after following the tutorial, nothing happens on selecting the weapons at the ui, check:
-That all the blueprints are like the images (especially after you change WeaponBackpackItem).
-That you added the weapons at BackpackWeapons.
-That you made right GetShooterGameInstance: http://i.imgur.com/78T6ivT.png
LikeLiked by 1 person
Despite everything working, I noticed the GetOwningActor node in the HeroFPP_AnimBP returns “None” ?
LikeLike
Even GetPlayerCharacter is giving “None” from the AnimBP, as I am controlling it. How is this possible?

LikeLike
https://answers.unrealengine.com/questions/126954/cast-to-character-failed-in-animation-blueprint.html
So I found this question on the answers site, where the guy states that the cast only fails when the AnimBP is open. (I know, crazy right?) but wow, as soon as I close the animBP editor, no more cast fails.
I did notice something else though, while the AnimBP is open, it actually both succeeds and fails in near equal portion.

If you then switch focus to another window (Making Unreal run in low priority mode) there are only cast successes, and when retaking focus, the fails return.
Never a dull moment with Unreal Engine :D
LikeLike