Skip to content

Files

Latest commit

 

History

History

SwitchWeapons

Pick Up and Switch Weapons

  • Unreal Version: 5.0.0
  • Template: Third Person
  • Project Name: MyProject

Switch Weapons Screenshot

This switching weapon example is a type of weapon structure where the character can only have one sidearm and one rifle at a time. When the player overlaps a weapon pickup the weapon will snap to the character and be added the players weapon map. This is not production ready code nor is it a perfect example of how a weapon system should work.

There's dozens of ways to pick up and switch items, and mileage will vary depending on a game's needs. I'm sure there are better ways of doing this, but this was the way I construtcted it and I learned a lot throughout the process. There's a variety of different engine and code features this example touches so I figured it might help.

The animations I used don't line up exactly with where the weapons are placed on the body, but that's alright, it gets the point across and we can always import other animations later

  1. Add Animation Starter Pack to project
  2. Add Military Weapons Dark to project
  • Each pack above should be free. When you click Add To Project in your Library's vault you'll probably need to click Show All Projects then select your project then select the latest version the asset pack provides.
  1. Add Inputs Inputs
  2. Retarget Skeleton mesh to be able to get the idle pistol, idle rifle, equip pistol, and equip rifle animations.
  3. Create montages of equip animations
  4. Create new C++ class from AnimInstance called MyAnimInstance
  5. Reparent Mannequin's AnimInstance parent class to MyAnimInstance
  6. Create sockets to hold the guns
  • Rifle Spine Socket Holster Rifle to Spine Socket

  • Rifle Hand Socket Hold Rifle in Hand Socket

  • Pistol Spine Socket Holster Pistol to Hip Socket

  • Pistol Hand Socket Hold Pistol in Hand Socket

  1. Update Anim Graph with layered animations. I layered the idle animations alternatively you can create animation blends Layered pistol idle
  2. Update Animation Blueprint with nodes for isHoldingPistol and isHoldingRifle
  3. Add AnimNotifies to the Equip Pistol and Equip Rifle animations at about half way through the animations Anim Notify
  4. Update Event Blueprint to fire the equip functions from the AnimInstance file. Anim Event Graph
  5. Create MyWeapon class
  6. Create Data Table that uses the WeaponData Struct and add a pistol and rifle
  7. Make Blueprint with parent PickupWeapon, add the row name and the data table variable and then drop them in the editor.

Helpful Links