Attachment System
A detailed guide on how to use the attachment system.
Last updated
Was this helpful?
A detailed guide on how to use the attachment system.
Last updated
Was this helpful?
The attachment system relies on two main components: FirearmAttachmentsManager and Attachment scripts.
The FirearmAttachmentsManager defines the currently equipped attachments for the firearm.
The Attachment script represents the specific attachment to be used, handling the properties and behaviors of each individual attachment.
The FirearmAttachmentsManager component acts as a data container for your firearm attachments. The attachments use the data stored in the FirearmAttachmentsManager to enable or disable themselves accordingly, ensuring that only the relevant attachments are active based on the firearm's current configuration.
In the FirearmAttachmentsManager component, you'll see a list of items. Each item has two fields: Type and Name.
Type specifies the type of the attachment (e.g., scope, silencer).
Name indicates the name of the currently active attachment for that type.
As shown above, there are four default attachment types: Sight, Muzzle, Stock, and Laser. If you have an attachment with the type "Sight" and an empty name, it will be enabled automatically, as its type and name match those specified in the FirearmAttachmentsManager.
With this cleared up, let's take a look at the Attachment itself. You'll find multiple fields, including Type and Name. If both of these fields match one of the items in the FirearmAttachmentsManager list, the corresponding attachment will be used and activated on the firearm.
The fields below Type and Name are all multipliers that affect the firearm's properties. For example, if you set Damage to 200, it will double the firearm's damage, effectively increasing its power. Similarly, other fields can adjust different aspects of the firearm, such as accuracy, fire rate, or recoil.
For the attachments to function correctly, they need to be parented to the firearm. Additionally, the firearm itself must have the FirearmAttachmentsManager component attached to it. This setup ensures that the attachments are properly recognized and managed.
There are several types of attachments, such as AttachmentSight and AttachmentMuzzle. For these attachments to work correctly, they need to be placed on the same GameObject as the Attachment component. This ensures that the attachments are properly recognized and interact with the firearm.
The fields in the attachment sight, change the aim and aim lean positions of the firearm (If the firearm has an Aim Animation)
There are two fields: Fire SFX and Muzzle Effects. Here's what they do:
Fire SFX: This field contains the firing sound effect. It overrides the default firing sound if the attachment is used.
Muzzle Effects: This field is for the muzzle effects (e.g., muzzle flash, smoke). It ensures that these effects are played when the attachment is active.
To create a laser attachment, attach the "LaserSight" component to the same GameObject as the attachment.
For a stock attachment, set the Type of the attachment to Stock and adjust the relevant multipliers, such as recoil reduction or stability, to modify the firearm's behavior accordingly.