Final Project Week 12 - Attachments

Last week I completed the recoil for my system. I implemented it into the hipfire and ensured that all of the variables worked as expected. Recoil was the last step towards creating a fully functional weapon system.


I started this week by looking at the different attachment systems in current games. I did this so that I knew which variables the attachments should affect and how they should be modified. I used Battlefield 4, Apex Legends and Ghost Recon Wildlands, I chose these games because they represent 3 different kinds of shooters. I also chose them because the modifications are all visual.

Battlefield 4

The attachments in Battlefield 4 all give a positive and negative effect, for example, there is a range of different grips, some will improve hip fire, but make aimed fire less accurate, while others will increase accuracy, but increase hip fire spread. they do this to balance the different attachments and to allow users to customise their guns to suit the style that they enjoy playing. I want to ensure that each attachment can change more than 1 value. This will allow users to have attachments change everything that they want.

Apex Legends

The attachments in apex legends all change 1 variable or group of variables. Some weapons can use the same attachments as others, however, the effects of the attachments are not always at the same scale. this leads me to believe that each weapon has a specific set of overrides for every attachment of every weapon. this would have been done to allow the developers to balance and tweak each weapon individually. This was backed up by the patch notes of recent patch notes from the developers of Apex legends where they say, "Shotgun Bolt rechamber rate has been reduced for the Peacekeeper only Level 1 mitigation 10% -> 7.5% Level 2 mitigation 20% -> 13% Level 3 mitigation 25% -> 16%"(EA, 2019). This not only shows that they have control over the stats of each attachment for each weapon, but also each level of that attachment as that same attachment is used on other weapons, with different effects.

Ghost Recon Wildlands

I chose Ghost Recon Wildlands because it is a very different game to the others, while battlefield and apex legends are multiplayer PVP games, Ghost Recon is a single player/coop game this means that they can change the effects of the attachments differently as they do not have to worry as much about balancing them. This means that you can use multiple attachments to affect the same stats more than once. This gives the user a lot of flexibility to make a weapon exactly how they want, for example, they can change an assault rifle to make it extremely accurate and have a lot  of range, but sacrifice speed of using the weapon and introduce more kick, or, you can make it slightly less accurate but reduce the kick and make it very quick to use. These are already able to be changed through editing the weapons base stats directly in my system, but I want to ensure that all of that is possible with the attachment script.

Implementing the Attachment Script

Variable Groups

I have split up the different variables into groups, these groups are variables that the developer would want to change together, for example, all of the sway variables have been grouped together because if they changed one, they would most likely want to change the rest. This helps the developer find all of the relevant variables that they want while also saving them time and reducing the change of making a mistake if they had to turn all of them on individually.


All values that can be affected by attachments have overrides, this allows the developer to create attachments that are suited to specific weapons, they have the ability to completely override the base values of a weapon with a value they can set themselves. A good example of this is a magazine attachment, the developer could make an extended magazine that has exactly 40 rounds instead of the base stat of 30. this also includes the different sounds and particle effects of the gun.


Not all of the variables that can be affected by the attachments have multipliers. The reason for this is different depending on the variable. variables such as sounds and particle effects obviously cannot be multiplied as they are not numeric values. The number based values that cannot be multiplied are the burst amount because that should always be set with an override and gun positions because not all weapon models are set up the same so a multiplier for 1 gun would not work the same as it would for another.

Applying the Modifiers

To apply attachments, I was originally going to put the code into the attachment script. This made sense as the attachment itself could call the code when it was created meaning that as an attachment is added to the weapon, the effects are applied. The problem with this, however, is that if the scripts are not called in sync, so a multiplier would be applied, then it would be overridden by another attachment, this is not how it should work, all of the overrides should be applied, and then the multipliers are applied to the overrides.

To fix this, I moved all of the code into the weapon script, this allows the weapon to first apply all of the overrides, and then apply the multipliers to the adjusted values. I set these up as public functions so that they can be called when they need, right now they are called every frame, this allows me to change values while the game is running and get instant feedback. This is very inefficient so in the future, these will be called only when needed, for example, when applying different attachments to the gun.

Custom Inspector

Now that all of the core functionality was in place, I did some testing. I ensured that every variable worked as intended. While everything worked as it should, Something that stood out as an issue was how confusing the inspector was.

While testing the attachment script, I found 3 main issues, the first was that each set of variables has a checkbox to enable or disable the setting, the reason for this is to reduce accidental overrides and multipliers, and also to optimise it so that useless multipliers aren't being applied. The issue with this is that it adds to the length of the inspector.

The next issue is that all of the values of the weapon have to be duplicated so that it can be used for overrides and multipliers, this resulted in an inspector that is just too long to be understandable. Below I have put screenshots of the inspector for the script.

Default Inspector for the Attachment Script
(Split into 3 for the blog post)

The third issue is that you can apply an override and multiplier in the same attachment. I don't want this to be able to happen, because the attachment would be multiplying the value that it has just overridden.

To fix all of these issues, I have created a custom inspector. This doesn't just fix the issues, this will also make the attachment more intuitive as you no longer need to interact with the checkboxes to enable or disable modifiers. They will automatically be set as you change the values.

New Custom inspector with no values set Attachment to reduce recoil and kick

What I have done, is create a dropdown menu for every group of settings. this will allow the developer to easily see all of the possibilities without having to scroll through a massive list. The dropdown menu will allow the user to choose between an override and a multiplier, dependent on if that value supports it, for example, the sounds will have only the option for an override. Selecting override or multiplier on a group of variables will expose the variables within it. This helps keep the inspector clean and hides the variables that are not relevant to what the developer wants.

You can find the project on GitHub here:


Battlefield V. 2018. PC [Game]. EA Dice

Apex Legends. 2019. PC [Game]. Respawn Entertainment

Ghost Recon Wildlands. 2017. PC [Game]. Ubisoft (n.d.). Drop down menu in Custom Editor - Unity Answers. [online] Available at: [Accessed 8 Mar. 2019]. (n.d.). Drop down menu in Custom Editor - Unity Answers. [online] Available at: [Accessed 8 Mar. 2019]. (n.d.). Editor Script Disable Toggle C# - Unity Answers. [online] Available at: [Accessed 8 Mar. 2019]. (n.d.). Unity - Scripting API: EditorGUI.indentLevel. [online] Available at: [Accessed 8 Mar. 2019].

Electronic Arts Inc. (2019). Apex Legends – March 6 Live Balance Update. [online] Available at: [Accessed 8 Mar. 2019].

Unity. (n.d.). Building a Custom Inspector - Unity. [online] Available at: [Accessed 8 Mar. 2019].


  1. Coin Casino Review & Ratings
    Coin Casino is one of 인카지노 the top online casinos out there and has over 25 years of experience in the online casino business. This casino offers over 1,000 Number of 제왕카지노 games: 2000Deposit งานออนไลน์ methods: Withdrawal, Skrill, Skrill, Skrill,


Post a Comment