Home

Awesome

ScriptableObject-Based Gun System

Learn how to create a ScriptableObject-based gun system from scratch for your game!

In this tutorial repository and accompanying video series, you'll learn how to make a configuration-driven gun system with ScriptableObjects that will be able to have:

Impact Effects are not in scope of this tutorial series. They are handled using the Surface Manager (tutorial video here).

Youtube Tutorial

Quickstart

If you're following along with the tutorial series, check out the appropriate branch for the video you're watching. main will be the latest version and each branch such as part-1 will be where a particular video ended.

Make sure to import the Unity Particle Pack after checking out this repository for all the bullet shooting and impact effects. You can import just the folder "EffectExamples" and ignore the rest of the files. This will prevent overriding all your project settings.

Most likely you will also need to run the Render Pipeline Material Converter since we're using URP and Unity Particle Pack (1.0-1.7) ships with only Built-In Render Pipeline support. These particle systems loop, so you may also need to turn off "Looping" on each Particle System in use.

As of April 4, 2023, this uses Assembly Definitions (tutorial) to package the files. If you are using Assembly Definition files in your project, you may need to add references to LlamAcademy.Guns, LlamAcademy.ImpactSystem, and if you choose to use the demo scripts, LlamAcademy.Guns.Demo.

You will need to download "Rifle Idle" and "Pistol Idle" animations from Mixamo or your preferred animation for those states. The demo Animator assumes these exist already. You may need to hook them up on the "Gun Layer" of the StarterAssetsThirdPerson.controller

Scope of the Project

This repository is primarily intended as a learning tool with the Gun Series. However, you can absolutely take this and use it in your game. There are some key limitations to call out as this repository grows and we cover more things that if you're just pulling this repo, you should be aware of.

This repository is focused on Guns and making a flexible gun system to support all kinds of guns. How they work, configuring them, ammo types, this kind of thing. The core functionality of the Guns are housed in LlamAcademy.Guns and sub-namespaces. Anything listed as Demo was implemented to showcase some functionality, and may not be fully thought through. It can be used for reference implementation but may have holes in functionality and may not work "out of the box" for your game. This includes the Player Controller. A fully functional Player Controller is not (currently) in scope of this repository. I am using the Starter Assets Third Person Controller and doing some basic integrations to show a starting point only. Having different states such as "aiming" is more of a character controller function than strictly the gun system function.

Pull Requests

If there is something broken on a particular branch (each video has a dedicated branch that ends at the end state of that video), please feel free to open a PR to address that problem.

Since this is intended as a learning tool more than an "off the shelf solution for everything related to guns", requests can be made, but new features will not be added without an accompanying tutorial.

Aiming

Starting with Part 12, Aiming with the Animation Rigging package was added, and right click to aim in the ThirdPersonController was removed.

Aiming is handled by clamping the camera rotation to relatively closely match what the player's rig can bend to. It's important to note as well that ShootType.FromGun does not work well with Animation Rigging and IK since it has the Gun driving the aim target position, and the IK / Rigging trying to aim the gun. If you want to use "FromGun" the Animation Rigging should be disabled or weights set to 0.

Animations

Animations such as Pistol Idle and Rifle Aim cannot be included in the repository. You can find the Pistol Idle on Mixamo for free labeled "Pistol Idle". They also have a Rifle Idle animation you can bring in as well.

Supporters

Have you been getting value out of these tutorials? Do you believe in LlamAcademy's mission of helping everyone make their game dev dream become a reality? Consider becoming a Patreon supporter and get your name added to this list, as well as other cool perks. Head over to https://patreon.com/llamacademy to show your support.

If you'd prefer to become a YouTube Member you can get all the same benefits on that platform!

Want to provide one-time support? You can send a Super Thanks on any video!

Phenomenal Supporter Tier

Tremendous Supporter Tier

Awesome Supporter Tier

Supporters

Other Projects

Interested in AI Topics in Unity, or other tutorials on Unity in general?

Requirements