Creating A Weapon
Constructing The Weapon Data
Weapons are stored as Data Assets in your project so that they can be easily loaded and unloaded when required. Setting up a new weapon should be fairly straight forward and with the addition of the preview window to see the changes in real time, should also be a quick process. To create the data, simply right click in your content browser window and select Gunsmith->Weapon Data. Using a consistent prefix for naming is recommended and we use WD_.
Once you have named the new weapon, double click on the asset to open the editor. At the top of the details panel you should set the Unique Tag and Weapon Type for your new weapon. The Unique Tag is the weapon identifier and will be used throughout the project to get this weapon again. The Weapon Type is what we use to tell the mesh which animation set to use. The default Manny is set up to use pistol and rifle animations.
Setting Up A Mutable Customizable Object
Browse to the Cosmetic tab in the Details panel and you should see that there are a few options here. Mutable is highly recommended over Skeletal Mesh as you get a lot of nice features such as dynamic Skeletal Mesh composition and async mesh streaming. Feel free to read through the unofficial docs by anticto for a better idea of what it can do.
To create a simple Mutable Customizable Object, create a new asset in your Content Browser under the Mutable heading and name it CO_YourName. The image below shows the minimum setup needed to display a single mesh and if done correctly, when compiled you should see a preview in the bottom right preview screen. The name you assign to the MeshComponent is the name we will need again in the Weapon Data Asset so make sure it is memorable.
Caution
Make sure you set the “Reference Skeletal Mesh” variable in the Mesh Component node or you will see an error when compiling.
With the Customizable Object set up, return to the Weapon Data Asset and set the Mutable Object to point at the new asset. The Mutable Component name dropdown should show the name of the new component you created and when selected should automatically attach it to your model. If you are using a custom editor model this may be getting attached to the wrong socket. You can change which socket this attaches to in the Project Settings->Gunsmith Settings under Weapon Attach Socket Name.
You should now see your character holding the weapon as expected but not yet shooting. Depending on your weapon asset, you may need to change the attach transform in the Weapon Data to make sure your weapon is pointing in the correct direction.
Adding A Projectile Emitter
We use emitters in the Weapon Data Asset to determine what the output of the user pressing the trigger will be. A Projectile Emitter is the most common type of emitter which we will use for this guide but a couple of other examples that you could use would be a Beam Emitter or maybe even a Shotgun Emitter if you only want to affect an area in front of the character rather than using individual projectiles.
To add an emitter you just need to find the Emitter array in the data and add a new item. Set this new emitter to the GSWeaponProjectileEmitter type which is just the base projectile emitter. Then set the Projectile Data to GSProjectileDataAsset. Manny will now shoot a projectile without any attached visual data. You can set a Damage Dealt value in the projectile Damage settings if you would like to test this dealing damage in a PIE session and also add your own visual state, either via the Cosmetic panel or by setting the Projectile Class which is the visual actor that will be spawned to represent the projectile.
Weapon Behavior Templates
Weapons are designed in a way that you can create and reuse behaviors between different assets. This allows you to share similar functionality while still giving the flexibility of changing variables inline. New templates can be created in your Content Browser->Gunsmith->Behaviors and should show up in the weapon behavior drop down lists.