Working with Attachments
Last updated
Last updated
Refer to this tutorial for instructions on working with attachments. This section of the documentation will cover the same steps in detail.
This is how you can add attachments using FPS Engine. First you will need a fully set up weapon, so if you do not have that, make sure to do that step first. Refer to
For this guide we will make a new “Barrel” using a simple built-in cylinder.
Open your desired weapon prefab and drag and drop your attachment model. For the sake of this guide, as said earlier, we will add a cylinder, and place it where the attachment is supposed to be placed, for ours, in the tip of the gun, as seen in the pic:
It is highly recommended to place attachments as a child of the weapon, so it moves with it. Now, select the attachment and add the appropriate Attachment script to it, you can choose from the following:
Notice that, inside your component, it asks you to assign an attachment identifier.
Each attachment requires an attachment identifier ScriptableObject, functioning similarly to Weapon_SO. If multiple weapons use the same ScriptableObject, they can share attachments. For instance, if two weapons share the same barrel type, both barrels are recognized as the same attachment because they share the attachment identifier ScriptableObject, even if they are part of different game objects within different prefabs.
To create a new unique AttachmentIdentifier_SO, right-click on the Project folder, then select Create → Cowsins → New Attachment Identifier.
You can set different parameters for your attachment, like the name, the icon of the pick-up graphics.
THESE PICK-UP GRAPHICS ARE ONLY DISPLAYED ON PICK UP OBJECTS, THIS IS NOT THE ACTUAL ATTACHMENT MODEL.
Once that is completed, return to your attachment and choose the attachment identifier we just created. You can also adjust attachment settings as desired. Keep in mind that these settings are cumulative, as multiple attachments may be applied to a weapon.
Next, navigate to the root of your weapon prefab and assign the attachment object (not the ScriptableObject) within the corresponding CompatibleAttachments section. In this case, place it under Barrels since it is a barrel attachment. Afterwards, ensure to deactivate your attachment to prevent it from being displayed on-screen.
If you want this attachment to be a default option, you can also add the attachment object to the appropriate DefaultAttachment slot. Since it's a barrel attachment, place it under DefaultBarrel to avoid potential unexpected issues.
Since we are making a Barrel, we will add Barrel.cs, note that all these scripts inherit from
Check for more information.