Search Unity

Tutorial - Make a ScriptableObject-Based Gun System from Scratch

Discussion in 'Community Learning & Teaching' started by ChrisKurhan, Oct 11, 2022.

  1. ChrisKurhan

    ChrisKurhan

    Joined:
    Dec 28, 2015
    Posts:
    268
    Hey all! Happy #TutorialTuesday!

    This week I'm kicking off a new series about guns! If you're going to have more than a couple of them in your game, you'll likely find a prefab-based workflow becomes cumbersome to keep cleanly structured and in sync as you extend functionality, add VFX, and want to reuse configurations. Learn how to make a highly configurable ScriptableObject-based gun system from scratch!

    In Part 1 I cover covering the base setup of hitscan guns starting with 3 scriptable objects:
    1. Gun Scriptable Object - holds the model, does the shooting
    2. Shoot Config Scriptable Object - holds how the gun will shoot
    3. Bullet Trail Config Scriptable Object - holds how the gun trail will appear

    Here's the Series Playlist:
    1. Part 1 - Shooting with a Gun Scriptable Object, Shoot Config, & Bullet Trail Config
    2. Part 2 - Procedural Recoil & Bullet Spread
    3. Part 3 - Deal Damage to Enemies and Objects with Guns
    4. Part 4 - Animation-driven Reloading
    5. Part 5 - Sound Effects
    6. Part 6 - Rigidbody Projectile Bullets
    7. Part 7 - Accurate Aiming & Crosshairs
    8. Part 8 - Dynamic Modifier System
    9. Part 9 - Explosive and Frost Rounds
    10. Part 10 - Attachments
    11. Part 11 - Gun Pick-ups
    12. Part 12 - Aiming IK
    13. Part 13 - Bullet Penetration

    If you have some other suggestions for content to be added to the playlist, leave a comment here or on YouTube! This should be a great foundation for you to be able to build really robust customizable gun systems for your games that your players will really love!

    ‍ As always, the full project for this video is available on GitHub!
     
    Last edited: Sep 12, 2023
  2. ChrisKurhan

    ChrisKurhan

    Joined:
    Dec 28, 2015
    Posts:
    268
    Hi all, Part 2 of the Series is up! In this video I cover Procedural Recoil / Procedural Bullet Spread with 2 methods - one that you commonly see implemented, based on random values on the X/Y/Z axis, and one based on a texture, to give you a more "predictable random" spray pattern! (link in first post)
     
  3. ChrisKurhan

    ChrisKurhan

    Joined:
    Dec 28, 2015
    Posts:
    268
    Great morning all, Part 3 is up! I cover damaging enemies and arbitrary objects by raising events when they take damage and attach different handlers for death as needed!
     
  4. ChrisKurhan

    ChrisKurhan

    Joined:
    Dec 28, 2015
    Posts:
    268
    Hello Unity developers, Part 4 is now up where I cover how to implement reloading. This seems like a very simple, straightforward concept, but there is some nuance to how the implementation can go!
     
  5. ChrisKurhan

    ChrisKurhan

    Joined:
    Dec 28, 2015
    Posts:
    268
    Hey all, Part 5 is now up where we'll add ScriptableObject-driven sound effects to our guns. We will play different sounds when for shooting with ammo, shooting out of ammo, last bullet in clip, reloading, and of course, impact sounds handled by the Impact System!
     
  6. ChrisKurhan

    ChrisKurhan

    Joined:
    Dec 28, 2015
    Posts:
    268
    Hi devs! Part 6 is up now where we'll update the system to also support both Rigidbody projectiles. This enables cool new guns like grenade launchers, rocket launchers...other thing launchers... and gives you the ability to add more realistic bullet physics like bullet drop and drag.
     
  7. ChrisKurhan

    ChrisKurhan

    Joined:
    Dec 28, 2015
    Posts:
    268
    Hi all! Part 7 is up now where we'll learn how to implement 3 popular options for aiming / shooting bullets, and accurately representing a crosshair!
     
  8. ChrisKurhan

    ChrisKurhan

    Joined:
    Dec 28, 2015
    Posts:
    268
    Great morning all! Part 8 is now up where you can learn how to create a dynamic gun modifier system that enables you to modify attributes of the configuration at runtime!
     
  9. ChrisKurhan

    ChrisKurhan

    Joined:
    Dec 28, 2015
    Posts:
    268
    Hey all, today is Part 9! You can learn how to make explosive and frost rounds (or really any bullet impact effect) using the Modifier System, Impact System, and Damage System we've implemented already!
     
  10. ChrisKurhan

    ChrisKurhan

    Joined:
    Dec 28, 2015
    Posts:
    268
    In this week's video (Part 10!), you can learn how to make an Attachment System in Unity for your guns, like what you see in games like Battlefield and Call of Duty!
     
  11. ChrisKurhan

    ChrisKurhan

    Joined:
    Dec 28, 2015
    Posts:
    268
    This week's video is a very commonly requested topic - how to have gun pick-ups in game! Check it out in Part 11!
     
  12. ChrisKurhan

    ChrisKurhan

    Joined:
    Dec 28, 2015
    Posts:
    268
    Part 12 and Part 13 are now up which include cool things like Aiming with IK + Animation Rigging, and Bullet Penetration!