# Attachment System

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.

<div align="left"><figure><img src="/files/nmghWzJhwEqFLMWiJUEo" alt="" width="547"><figcaption><p>Firearm Attachment Manager component</p></figcaption></figure></div>

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.

<div align="left"><figure><img src="/files/n9SfxgPrIQHLInWAN1wQ" alt="" width="563"><figcaption></figcaption></figure></div>

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.

{% hint style="warning" %}
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.
{% endhint %}

## Attachment Types

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.

### Attachment Sight

The fields in the attachment sight, change the aim and aim lean positions of the firearm (If the firearm has an Aim Animation)

<div align="left"><figure><img src="/files/FUOxPCSdsikPa29HL2kl" alt="" width="563"><figcaption></figcaption></figure></div>

### Attachment Muzzle

{% hint style="info" %}
Currently, this component is named **"Muzzle"**, but it is planned to be renamed to **AttachmentMuzzle** in the future for better clarity and consistency with other attachment components.
{% endhint %}

<div align="left"><figure><img src="/files/YaRP3EwYtiaE3GEINpZ4" alt="" width="563"><figcaption></figcaption></figure></div>

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.

### Other

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.

{% hint style="info" %}
If you're creating a custom attachment, you can use **Attachment.IsActive()** to check whether the attachment is active. This allows you to enable or disable the custom attachment logic based on whether the attachment is currently in use.
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://akila.gitbook.io/fps-framework/tutorials/character/firearm/other/attachment-system.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
