โAttachment System
In this section you will find more about attachments.
Last updated
In this section you will find more about attachments.
Last updated
The demo project provides a simple attachment system, which allows you to change them in realtime. Make sure to press the "I" key, and the attachment editing mode will be activated.
At the current state it is possible to change 3 types of attachments:
Barrel-type attachments
Grips
Scopes
To cycle the attachment type make sure to press 1, 2 and 3 respectively.
All attachments are located in the weapon prefab:
Barrel and Grip Attachments properties contain a single group of attachments of the same type. You can cycle attachments by pressing 1, 2 or 3 keys. For example, if you press 1, the next grip attachment will be equipped.
Scopes, however, are different. Instead of containing a single attachment group, they contain a list of attachment groups. That is because scopes usually have more sockets on the weapon, than grips and barrel attachments.
Make sure to add scopes with different sockets as separate groups, otherwise you will not be able to change sights in game.
All attachments are derived from the BaseAttachment class:
attachmentLayerSettings deifne a list of animation features, which we want to link when the attachment is equipped.
BaseAttachment is used for barrel and grip attachments, as these typically do not require that much logic.
Scopes have their own attachment type:
aimFovZoom will be multiplied by the default FOV when aiming.
sensitivityMultiplier will scale the player input when aiming.
aimPoint defines the active aim point socket.
AttachmentGroup represents a set of attachments, usually of the same type. This class is used to initialize, cycle and get the active attachment.
This class is generic, meaning that you can use any BaseAttachment-derived type. This is a good foundation for custom attachment types.
The process is quite straightforward:
Add the attachment prefab to the weapon.
Add the BaseAttachment or ScopeAttachment component to it.
Then, based on the attachment type, add your attachment to the list.