The Weapon System


George LeMaster - 03/24/2023


Obviously, you can’t have a shooter without weapons. Hard coding a weapon is simple enough, the challenge here is figuring out a good, streamlined, modular way to implement an expandable, customizable multi weapon system. The solution? Scriptable Objects.

Scriptable Objects behave a lot like classes, you can create instances of them and store data within them. The big buff for SOs is that you can save them as essentially prefabs, end edit them within the Unity editor. This makes them ideal for items that call on a lot of other assets in your project, like weapon sound effects of models, in this case. 

The way the code takes this and makes it usable weapons is quite simple, at least in theory. Just create a reference to a scriptable object of the  type you want to use, and set that equal to your desired object, when you want it. From there all your data is ready to be used an manipulated. For example, each weapon SO has a GameObject member that stores the in game graphics for the guns. After you set the objects up, just spawn and despawn these graphics as needed when swapping weapons. Nice and modular, so whoever we add a new weapon to the game, you can just make a new Scriptable Object and hook up its info. It’s so easy, any member of the team could do it, not just the person who wrote the system!

Get 731

Leave a comment

Log in with itch.io to leave a comment.