Attachments
An attachment is a data asset that is applied to a weapon at runtime to modify the attributes that it has registered.
Setup
To create an attachment, click on the Gunsmith->Attachment Data
selection in the Content Drawer.
After opening the attachment, you will be presented with a few categories. In this example a multiplicative modifier is being applied to all attributes that have been assigned the Weapon.Attribute.Example tag. Adding a name to each attachment is also recommended.
Applying An Attachment
There are three functions exposed to add an attachment to a weapon, the first is via the EquipData in EquipWeapon. The equip data has an Attachments array which you can specify the attachment class and level for the attachment to be equipped with. If using the DefaultEquippedWeapons parameter on the Shooting Component, this is the function that will be called.
The second is SetAttachments and can be used to replace the full attachment array at the designated slot. A slot index of -1 can be used here to apply attachments to all weapons. The AppliedFrame parameter exists to specify a frame for the attachment to become active on as it’s crucial that the predicted client and server apply the attachments on the same frame to prevent any reconciling. Leaving the AppliedFrame parameter at -1 will apply the attachment instantly so this should only be done if you can ensure the player is not actively using the weapon to prevent any client/server desyncs.
The final function is AddAttachment which will just add the new attachment to an existing attachment array. This requires slightly more management from the user as it’s possible to add multiples of the same attachment. The same rules with the slot index and AppliedFrame params apply here too.
There is also a RemoveAttachment function which does as you’d expect, removes the matching attachment from the array on the specified frame. This function requires a AttachmentID parameter which is assigned to the attachment instance when it is added to the shooting component. It also has a AppliedFrame parameter to ensure the attachment is removed at exactly the same time on both predicted client and server.
Executions
Executions are additional functionality that can be added to an attachment. This would typically cover anything that an attribute does not, such as spawning a new projectile if a target is hit.
Apply and Remove functions are exposed to be overridden so that the user can bind to any relevant delegates as needed.
Modifying the Weapon Mesh
Tags can be assigned to attachments to modify the Mutable mesh when they are applied.
Each tag is passed to the GSWeaponSkeletalMeshComponent which will then split off the last two sections of the tag to use as the Mutable parameter name and value. The Mutable instance is then updated with these new values which can be referenced in any Data Tables or controlled via Object Groups. For example, Weapon.Attachment.Scope.Default
would set the Mutable parameter Scope
to the string value Default
.
Note
This system is still in development so may not suit more complex setups yet.