⚙️
FPS Framework
Asset StoreFab
  • Get Started
    • Welcome!
    • Setup
  • Tutorials
    • Character
      • First-Person Controller
      • Inventory
      • Firearm
        • Basics
        • Advanced
        • Other
          • Spray pattern
          • Attachment System
          • Projectile System
      • Explosive
    • Systems
      • Audio System
      • Animation System
      • Interactions
        • Pickable
      • Save System
      • Settings System
    • Tools
      • Extension Methods
    • UI
      • FPS Counter
      • Get Name
      • Image Size Fitter
  • Other
    • Full Change Log
      • 2025 Change Log
      • 2024 Change Log
      • 2023 Change Log
      • 2022 Change Log
Powered by GitBook
On this page
  • Attachment Types
  • Attachment Sight
  • Attachment Muzzle
  • Other

Was this helpful?

  1. Tutorials
  2. Character
  3. Firearm
  4. Other

Attachment System

A detailed guide on how to use the attachment system.

PreviousSpray patternNextProjectile System

Last updated 2 months ago

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.

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)

Attachment Muzzle

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.

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.

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.

Firearm Attachment Manager component