Some of this I have implemented myself, but never before with Scriptable Objects, which sounds like will allow for much more customizability and expandability. Excited for this series!
One of the best things about your tutorials is finding out about new/old things that I never even knew about in all my time of using unity. (case in point, native unity Object Pools?!?!?!?! This is so cool!!!)
Thanks 🙏! Gravity will come with projectile-based weapons in the future. I covered bouncing bullets before here: ruclips.net/video/GkStW8-Q5P0/видео.html I wasn’t planning to cover it in here, but that’s an interesting idea to consider to have it all in one place.
You can do that, but usually bullets have relatively low mass and high velocity which makes the normal hitscan ray cast “good enough” of a simulation. If you really want to add it, you can follow the concept of this video: ruclips.net/video/8mGZBYsSXcQ/видео.html and it will give you the result you’re looking for.
For those of you wanting to use this for an FPS, configure the player camera to be the raycast start point, from what I've heard making the camera the start point fixes a lot of inconsistencies with aiming
Hell yeah. This is amazing :D Once the series is over, something similar for an ability system (think League of Legends for example) would be sick. I've been doing some research lately and there isn't much valuable content about it. Maybe it's a good challenge and opportunity Anyways, thanks for your awesome work!
❤️! That’s a great idea! I have a real life use case for that, so maybe once I get some time to play with it and see the challenges I can put together a series on it!
Thanks man! The create tail and render trail funcion and the variabels was very useful for creating the perfect trail. It's always better controlling it with the code. Learnt alot and I could now use this in my own game to create good looking bullets. Thanks!!!!!!
Great, what a brilliant brain you have to create such sophisticated system and you been so kind to share with us. Thank you a lot mate. You are amazing.
The "ParticleSystem" named "ShootSystem", what is it? is it a particle system nested somewhere on the gun prefab? is it for the muzzle flash? Could you please point me to the video that explains the muzzle flashes and/or the "ShootSystem"? Thanks in advance for the information.
Hey! The ParticleSystem named ShootSystem is gathered at the time of spawning the gun into the world. I set it up in the code around time 6:20. Around 16:25 I talk about the prefab configuration of the glock and m4. I didn't talk too much about the positioning of it, but you should place it where you want the bullets to spawn, so close to the tip of the muzzle. The assumption here is the muzzle flash and the bullet spawn point can be the same place In your other comment, in that video we drag references in the Inspector, which I tried to avoid here, instead I'm opting to pick it up automatically on Spawn.
@@LlamAcademy I downloaded your github repo and opened it in the same unity version. Looks like the MuzzleFlash01 is having issues (missing Prefab with guid: numbers-blah-blah. Sadly it keeps me from trying out your system :( ... Thanks for the tuts though, very nice!
Hi, I am trying to follow this great tutorial, but at 11:34 you use (SurfaceManager) and it is showing up as an error for me. I do not know where in the video this class was created, hope you can get back to me on this. :)
In this video I DO NOT cover the Impact System: ruclips.net/video/kT2ZxjMuT_4/видео.html you can check out that video for the full explanation for how that works! That’s for the SurfaceManager and ImpactType both. If you’re not interested in using that system for impacts, feel free to just remove that code! Everything will still work! PlayerIK is a very simple demo script implemented solely for the demo. As I mention in the video, this will be covered in the future, so you can skip that part for now, or check out the project on GitHub to see that naïve implementation. Edit: Aiming IK is covered in depth here: ruclips.net/video/chgLRjSaoXc/видео.html
Yes there is a tutorial, that’s linked above. It also has the GitHub repository in the description of the video. This video also has a GitHub repository that includes that code.
Wouldn't the GunType enum prevent you from updating the game over-the-air (like you mentioned in 1:50)? Adding a new gun type would require you to update the code and thus require a new build. Since you're using it as a unique identifier, a string or integer might be a better fit. Just need to remind the designer to make the identifiers unique (or write an editor script to automatically fix them). Otherwise pretty great tutorial. Straight to the point and very little to no fluff.
Yes you are correct! In the final section I discuss ways to solve that problem. Specifically, I talk about how you could use the "Name" parameter on the GunScriptableObject to match against in place of GunType. Edit for some more context: For most developers, that's not going to be within the scope of what they'll implement. Typically I don't like "magic strings" that have significant meaning, so I implemented the GunType to have a declarative way to match the guns for the majority of users, and in the end of the video I talk about how you can support the over the air updates by using the Name as a "magic string"
@@LlamAcademy Alright I missed that part. The real solution to avoid magic strings would be to have an editor tool that automatically populates the identifiers with Guid or something similar but that's way out of this video's scope. Might be an interesting topic in the future though. I feel like editor scripting in general is not discussed a lot.
In GunScriptableObject.cs, why is the TriangleIndex set to 0 directly in the following line? SurfaceManager.Instance.HandleImpact( HitCollider.gameObject, HitLocation, HitNormal, ImpactType, 0 ); Won't this result in incorrect impact results if there are multiple submeshes?
21:00 so my question here is, I've tried putting assets in the Resources Folder before, and then created a folder hierarchy within it, and couldn't reach the hierarchy. What do I need to do to reach the hierarchy or is that what addressable resolves? This is effectively my second week in Unity and I am trying to learn C# principles as well as how Unity functions, so forgive me if this question is obvious, or incomplete.
For resources folder you can load with the path name to the file without “Resources”. Resources are bundled on build, so if you include everything there, you can easily reference them. Addressables allow you to extend the game without needing to rebuild the whole game.
@@LlamAcademy awesome, I saw some videos, that were not beginner level, and it seemed like that was the next step in my programming journey after the basics! Thanks for confirming that!
Usually that’s because the gun scriptable object was not converted from “: MonoBehaviour” to “: ScriptableObject” or the [CreateAssetMenu] tag is missing, or improperly defined (such as copy/paste issue with multiple SO with the same path)
@@LlamAcademy i did everything correct as you said but still doesnt work i grabbed the code from your github so its copy pasted, i dont know what to do now, if you are ok on communicating on discord so i can show you a picture of the error. it would be the easiest method.
Hey Chris, how do you plan these Systems? This Guide is honestly pretty damn good. Do you just start by coding some of the ideas until you have a working prototype or do you plan these systems upfront and if so got any tips on how to design systems?
My planning for systems is probably not the ideal model. I typically think about things for...between seconds to minutes then get started working on it from basically just the "idea". Usually it works out okay, but there are some holes or problems that I refactor as I run into the limitations of whatever the initial design was. For this system I had already done that full process of design, implementing, & refactoring in my old (now unpublished) mobile game Llama Survival. I had already identified a bunch of the problems & solutions that I couldn't or wouldn't solve in the first implementation for that game, and that was the starting point for this tutorial series. I think what works best for you really depends on whether you like to plan all the details out ahead of time, or you like to just get into the weeds and figure it out. The latter has a higher risk of rework and the first iteration usually has some problems. I just like to just get started on things 😅. That's more rewarding for me than spending a ton of time on the initial design.
@@LlamAcademy Thanks for the insights. Yeah what I've found to be working quite good is a mix of both. Just thinking about what I need on a high level and then get right to work. When I feel like I'm stuck I iterate on my design and try to fix things on paper before I code again. When I just code before having a high level overview that's usually when shit starts to blow up for me 😅
I have a question. Maybe someone can help me. But first a big thank you for the great tutorial! The raycast is performed at the beginning of the shot. How is it supposed to catch an moving object like an enemy which is at that point not in line with the raycast?
When using a Raycast you perform all the hit detection on the frame you click, everything after that is just VFX that happens after the fact to show the player something is happening :) If you shot them where they were that frame, it should all be good. If not, then you missed!
Hello! I have a little issue with trails, i tried to apply your system in my fps project, and it mostly works, but i can't see the bullet trails in game mode. Through editor i can see that they're actually going out of my gun(not the actual trails, but the objects, when i select them in editor) in right direction(i think it happens because i use 2 cameras, 1 of it actually renders weapon and all its children in overlay. But i have a problem with muzzleflash's child in weapon prefab, its not applying to layer for player weapon, that might be the issue, but i am still not sure). Sorry if my comment seems incorrect, English is not my native language.
I'm still looking for a solution, but as far as I can tell, the problem is not related to layers and cameras, because no matter what layer is selected, objects in it are always rendered except bullet trails
In the GunSo you have ImpactType and SurfaceManager, which appear to not be a part of the unity engine. where did you make those or get those classes/objects from? Same with PlayerIK in PlayerGunSelector
👋 Hi! PlayerGunSelector we implemented in this video. When I talk about SurfaceManager / ImpactType I mentioned it was covered in another video (that’s linked in the description). The full project is on GitHub so you can view all those files. A better version of the PlayerIK will be done in a future video. As I said, It was really just for the demo to look nicer with the hands actually on the gun
Hello. As I said above you can find the SurfaceManager and ImpactType on the GitHub github.com/llamacademy/scriptable-object-based-guns/tree/main/Assets/Scripts/Surface%20Manager If you would like to understand how those are created, you can check out the associated tutorial: ruclips.net/video/kT2ZxjMuT_4/видео.html These can be completely skipped and ignored if you do not want to use that impact system without any additional loss in functionality. PlayerIK is also in the repository: github.com/llamacademy/scriptable-object-based-guns/blob/main/Assets/Scripts/PlayerIK.cs, but again I don’t recommend relying on this because I just quickly put it together without much thought. Later in the series we’ll probably review a better implementation. In this video I covered PlayerGunSelector at 13:00. You can always check the chapters at the bottom of the video to see each section.
Having 'LastShootTime' in the SO itself, won't that cause problems when there are multiple instances of 'PlayerGunSelector'? For eg:- Let's say we use this system to equip enemies with weapons and there are multiple enemies with M4, but there is only on 'GunScriptableObject' of M4. Won't changing the 'LastShootTime' for one enemy change it for all enemies? or even in a multiplayer scenario, won't it cause a problem?
Good question. In this video we didn't get into solving that problem, but you are right you will need to clone the SO or create instances to be used at runtime. Later on in the series we tackle that.
@@LlamAcademy oh that's nice. I didn't check the whole series as I just wanted to check the design pattern (even tho I have watched this video several times, i keep coming back. lol). Seems like I should put in proper time to watch the whole series.
why wont my private ObjectPool TrailPool; work this is the error Assets\Scriptys\GunScriptableObject.cs(21,13): error CS0246: The type or namespace name 'ObjectPool' could not be found (are you missing a using directive or an assembly reference?)
You need to stop doing everything uprfront. It is soo hard to figure out what is actually happening when you just spend 10 mins rattling off a bunch of code. Make it by following the logic of the functionality instead of setup then implementation. Start with a basic implementation and then add complexity on top of that. You might as well just have people download the files because this isn't really teaching the concepts from the ground up it is just rote memorization of how to do a very specific type of thing.
I do not have the IK tutorial yet, but you can check out the project from GitHub and review this implementation as a quick and dirty get started point!
I don't know how to fix that problem... Can anybody help? GunScriptableObject.cs(9,9): error CS0246: The type or namespace name 'ImpactType' could not be found (are you missing a using directive or an assembly reference?) PlayerGunSelector.cs(16,10): error CS0246: The type or namespace name 'PlayerIK' could not be found (are you missing a using directive or an assembly reference?)
Hi 👋. The impact system won’t be covered in this series because it was covered in this video: ruclips.net/video/kT2ZxjMuT_4/видео.html The full projects for all my videos are available on GitHub, so you can download those scripts from here: github.com/llamacademy/scriptable-object-based-guns (links also in description). Since this video is part 1 only, you may change the branch to “part-1” to only see what you see here. Good luck!
Hey LlamAcademy, i love your video. however i have one small issue when adding public ImpactType ImpacType; i get the error CS0246: The type or namespace name 'ImpactType' could not be found (are you missing a using directive or an assembly reference?). is surface manger a addon i need to add to my unity project???
Hi! thank you for this tutorial. I'm a newbie in unity coding so I followed each script closely but somehow still cant get the create -> guns menu show up on my end. I tried looking at the scripts from your github but it seems it's a more refined version of the scripts for later part of this tutorial series.. There's an error log saying "failed to find entry-points" with long logs under it (which I don't understand) If anyone encounter the same problem or have an idea on its solution, please help ;-; Update: I solved it but I have a question about the PlayerIK script as it won't show up on the inspector and gives error logs... please help ;-;
Great series. Learning a lot about scriptable objects. I do have one question however. In the repository there are a number of "Editor" scripts that aren't explained in the video and it appears the SO scripts won't function without them? thx
You do not NEED any of the editor scripts for them to work, but they make it easier, faster, and more convenient to set stuff up. How the custom inspectors are done are covered in these: ruclips.net/video/3w9iXT6wx5g/видео.html & ruclips.net/video/moXvNj7QUHE/видео.html Each video in this series has its own branch in the github repository so if you want to see just what was done in video 1, check out branch "part-1"
I couldn't finish my code relying this turorial, but thanks, it's really cool video. I faced mistake when I tried make ObjectPool(CreateTrail) - now we need to provide a second argument "actionOnRelease". I can approximately imagine how to do it, but anyway it's a bit complicated to me).
Hmm... the 2021 Object Pooling system should not require you provide the secondary argument. If you want to understand more about the 2021 Object Pooling system you can check out my full tutorial on that: ruclips.net/video/zyzqA_CPz2E/видео.html For any shooting system, I highly recommend using an Object Pool to eliminate garbage and keep your game running smoothly
the problem i am having is i am having a virtual camera that follows character positioned at characters back....show only characterss back portion will show now during swipe code of look functionality of starter asset its rotating in every angle so may characters side and front portion is visisble ...is it possible that any swiping character also rotate on camera direction...so only back portion of character will be seen..please help
I have a two errors Assets\Scripts\Gun\PlayerGunSelector.cs(15,12): error CS0246: The type or namespace name 'PlayerIK' could not be found (are you missing a using directive or an assembly reference?) & Assets\Scripts\Gun\PlayerGunSelector.cs(15,12): error CS0246: The type or namespace name 'PlayerIK' could not be found (are you missing a using directive or an assembly reference?) can some help plz Other than that its a good tutorial
Hi. There’s several comments around this one. In this video I DO NOT cover the Impact System: ruclips.net/video/kT2ZxjMuT_4/видео.html you can check out that video for the full explanation for how that works. In there we create the SurfaceManager and ImpactType. If you don’t care yet about impact effects, you can safely skip those and you will still be fine 💪
Ive finished the code, im having trouble with line 42 of gunscriptableobject shoot() saying object refernce nnot set to an instance of an object. i need help :(
i know this is a relatively old video but i wonder how can i change so instead of using the GunType enum to hold different guns, instead serve as a way to differentiate shooting modes, something like: enum GunType{ SemiAutomatic, Automatic, Burst } I think i should have different Shoot functions and use a Switch to select the shooting mode depending on what GunType the Gun is assigned to, but i'm afraid that having 3 functions with almost identical code is a bad way to do this, so i don't know how to approach this
In my game to differentiate between burst and automatic I applied a modifier to the gun to adjust the mode, "number of bullets per shot", and increased the delay between shots by 3x. In the "Shoot" function all I did was check if it was "burst" and started a coroutine to spawn 3 bullets over the course of several frames instead of 1 in a single frame. The outcome is minimal changes to "Shoot" and the rest of the gun system remained unchanged. Later on in this Gun Series I cover a modifier and attachment system that can help achieve this effect (around part 9 & 10). I didn't do Semi-Auto in my game, but I think that is possible to handle by just tracking if the player has at least 1 frame where they were not pressing "shoot" then proceed with the current code flow
Hi, I think the system is not that extensible, the gunSO would not work as expected because only one of its kind is allowed to spawned in the scene, what if your enemies also have that same gunSO ?
@@LlamAcademy Hi Chris, thanks for your answer, just to clarify, to clone the SO we have to change from this - gunSO = guns.find(...); - gunSO.Spawn(...) to this ? - gunSO = guns.find(...); - newGunSO = Instantitate(gunSO) - newGunSO.Spawn(....)
Sorry. I don't think in this video we got into cloning the SOs in this video. Yes, you will need to do something like that. I don't remember the exact video but later on in this series we get into that, probably when we get into modifiers/attachments.
Do you have a weapon manager video? I don't think there exists one on youtube. For choosing and equiping a weapon before the match starts, or as we spawn like in Valorant.
Hey, thank you for the tutorial, I am new to unity and have tried to follow this for a couple of hours but have hit an issue, I'm not sure if it's due to me not using your SurfaceManager and Impact Manger, I have followed along and typed the code out exactly although I'm receiving this error while attempting to fire; NullReferenceException: Object reference not set to an instance of an object GunScriptableObject.Shoot () (at Assets/Scripts/Weapons/GunScriptableObject.cs:39) PlayerAction.Update () (at Assets/Scripts/Weapons/PlayerAction.cs:12) I've since tried copying your code from github and replacing the 6 files creating in this tutorial but I had the exact same error so I think I have missed something in the setup in Unity but I'm at a loss as to what if you have any advice I'd appreciate it. I've also tried importing Unitys particle system as recommended to another commenter but it didn't change anything.
Can you give me the code at line #39 of GunScriptableObject.cs? From the repository on part 1 that is not a line that can give any error. If it is: Vector3 shootDirection = ShootSystem.transform.forward + .... It is important that your Gun model has a Particle System as a child of it and is positioned at the tip of the barrel. This is where all bullets will spawn. If you do not do this, ShootSystem will be NULL and give you that error. We assign ShootSystem on Setup() by doing: ShootSystem = Model.GetComponentInChildren(); which requires that the Particle System is a child of the instantiated gun prefab model.
Does this project differentiate which kind of interaction to use for which weapon? Like how a glock is semi, an m4 is automatic, a laser gun is charge/release
Not really. The gun system supports any of these, but the player interaction with the gun system is left to the implementer. If you would like these “fire mode”s I’d recommend to add that to the ShootConfigSO and read it on your “PlayerInput” and use that to determine if the gun.tick() should be called
So if I not implement the part with the Surface Manager (the vid in the info) i have no visuals… so I have to watch the video and implement the surface manager etc right?
You will not have impact effects, but you can also just pull the surface manager off GitHub. It’s included in this repository as well as the dedicated surface manager video repository.
Awesome tutorial! Quick question, I've used the system for a RTS game, but I can't seem to figure out why does the duplicated unit detects an enemy, the original shoots. Any thoughts? Thanks in advance!
I'm getting this error: " NullReferenceException: Object reference not set to an instance of an object at UnityEngine.Rendering.Universal.UniversalRenderPipeline.SetupPerFrameShaderConstants () [0x00089] in :0 at UnityEngine.Rendering.Universal.UniversalRenderPipeline.Render (UnityEngine.Rendering.ScriptableRenderContext renderContext, System.Collections.Generic.List`1[T] cameras) [0x00065] in :0 at UnityEngine.Rendering.RenderPipeline.InternalRender (UnityEngine.Rendering.ScriptableRenderContext context, System.Collections.Generic.List`1[T] cameras) [0x0001c] in :0 at UnityEngine.Rendering.RenderPipelineManager.DoRenderLoop_Internal (UnityEngine.Rendering.RenderPipelineAsset pipe, System.IntPtr loopPtr, UnityEngine.Object renderRequest) [0x00046] in :0 " when i'm playing on build
I would really recommend to use some form of object pool for this. In my earlier videos when 2021 wasn't out I made a simple one you can use (video: ruclips.net/video/fsDE_mO4RZM/видео.html code: gist.github.com/llamacademy/e3ed9e647b2c703d698a809d00a112a8 ) If you don't want to, you can use Instantiate/Destroy instead of getting objects from the pool and disabling them.
the Object pool keeps showing this error: "The type or namespace name 'ObjectPool' could not be found (are you missing a using directive or an assembly reference?)"
We’re using the Unity 2021 object pooling system here. As long as you are on 2021 LTS or higher you should be able to add “using UnityEngine.Pool;” at the top of the script and it should work for you.
@@LlamAcademy i see it, thanks , btw im having a mistake with the prefabs, MuzzleFlash01 is missing, the model suposse to have it right? i download the github`s First version but is has the same problem
When i try to change active gun while game is running it says "The variable ShootSystem of GunScriptableObject doesn't exist anymore." what can i do to change my gun while game is running
That's a more complex answer than I can probably reasonably do in a comment. I am planning on adding a video in the series about weapon swapping because that is a very commonly requested topic!
I am getting errors saying Assets\GunScriptableObjects.cs(135,50): error CS1002: ; expected Assets\GunScriptableObjects.cs(119,15): error CS1513: } expected Assets\GunScriptableObjects.cs(119,15): error CS1002 ; expected Assets\GunScriptableObjects.cs(52,48): error CS1001: identifier expected Can you put the scripts in a GitHub, or type it in the Description because i have no idea what this means :/
Hmm… from this video GunScriptableObject does not have 246 lines of code. Can you please review your implementation compared to the part-1 branch? github.com/llamacademy/scriptable-object-based-guns/blob/part-1/Assets/Scripts/Gun/GunScriptableObject.cs
Mr. Chris sorry to bother you but where on github can I download all the most recent scripts for this shooting project. I thought I downloaded all the scripts but the code has errors in surface manager and a few other places
Hi! If you download the project from github.com/llamacademy/scriptable-object-based-guns and follow the setup instructions there (downloading Unity Particle Pack for example) it should work with no errors. Each video has a branch with exactly what you saw on that video. For this one, at the top left where you see a dropdown that says "main" you can change that to "part-1" and it will reflect exactly where this video ended. If you download the latest "main" and it has some errors, can you share those exact error messages along with your version of Unity so I can troubleshoot those? It should be very easy to get working.
I did the same thing you did in the video, but it didn't work, only the gun was on the player's body. I deleted them with impcat type , player ik or something . Can you post the player ik script file? and can you solve this problem of mine please because we will enter the game contest
Hello, I am having an error with this line of code remainingDistance -= TrailConfig.SimulationSpeed * Time.deltaTime; It says that TrailConfigurationScriptableObject does not contain a definition for SimulationSpeed. Is there any import or something that i missed? Any ideas of how to fix this?
Seems like on the trail config you missed a step. Double check that section and what you have defined versus what is in the GitHub repository: github.com/llamacademy/scriptable-object-based-guns/tree/part-1
Awesome video! Just wish explanation would be little bit slower. My brain had to switch to second gear to keep with the pace of video. Other than that great job!
It's always a fine line to walk between "too fast" and "quit droning on and on". I'm generally a fast paced person so I guess it comes through in the videos sometimes 😅
Hi, i'm getting this error "MissingReferenceException: The variable shootSystem of SO_Gun doesn't exist anymore." after a few seconds on play mode, but i don't know how to fix it, somebody can healp me?
Hi, I'm using your ScriptableObjectBased Gun System on FPS game. When I walk and shoot at the same time, the bullet trail came from behind the gun(kind of behind camera). I tried to fix it by changing the startPosition of Trail at the begginingof the BulletTrail Coroutine, but it was same result. And also, when walk left, walk right and shoot at the same time, bullet trail start from air too, Do you have any idea how to prevent from happening these. Thank you for your great tutorial.
Hey! I think someone else asked about that in the comments of one of the videos, but I can't seem to find it now. In most games, this "problem" exists because the player and the gun are moving. Even though we spawn correctly from the barrel of the gun, that was at a snapshot in time. I looked into several other AAA games to see if this was something of an oversight that I had or what the deal was. It turns out even AAA games either: have this problem, or mitigate it by having extremely short bullet trails. The solutions I see are: 1. Leave it alone and have this "problem" - it can be mitigated somewhat by having smoke or something that comes out of the barrel afterwards to mask the effect. 2. Have very short lived bullet trails - player can't see the "problem" 3. Bind the start position constantly to the barrel of the gun (this results in "bending" of the trail which may not be desirable).
It's how we manage impact effects. That was covered in a separate video and has a dedicated github repo. More details in description and the pinned comment.
Hey @LlamAcademy I was hoping to get the github version of this project working, as it was awesome to see it graciously provided and I was looking to compare my current system which has been built upon from your previous tutorials. I just had one problem, it doesn't seem to be explained how I go about importing Unity Particle Pack into the project without destroying the settings. Also awesome production quality on these videos B)
Hi! Great question, and a common one. The Unity particle pack can be imported without overriding settings if you deselect all of the project settings files (they’re like the last ones). If you only select the folder about Effect Examples you will only get the particle systems, materials, and textures
@@LlamAcademy Thanks for the quick reply! Got it working great now as long as the hilarious aiming isn't caused by me, I could see this whole looking down+aim bull in a china shop movement mode working quite well if implemented as a feature XD CHARRRGE hahaga. As it's a common question it could be nice to have a quick explanation added to the github's "Quickstart", including updating materials. Looking forward to seeing how far this series goes!
😁 the movement and aiming is not particularly well implemented. It was a quick hack job just to get something there while we implemented the core “gun functionality”. Coming soon - accurate crosshairs! Movement still will be crazy while aiming but the aim will be right. Sorry! I meant to say as well, I will update the readme with that info!
I use the Unity Starter Assets Third Person Controller assetstore.unity.com/packages/essentials/starter-assets-third-person-character-controller-urp-196526 It's free!
Hey! This tutorial looks great, but when I download it from Github, it keeps giving me errors. I think the issue is with the MuzzleFlash particle system in the gun previews
Hmm.... usually the only way I can get that to happen is if I don't wait a frame before reactivating the TrailRenderer. Can you compare what you have to what is on Github: github.com/llamacademy/scriptable-object-based-guns/tree/part-1 ? And if you get the same behavior with that, show me a short video of what is happening and what configuration you are using?
@@LlamAcademy I'm having this same issue, the trail shoots to the last shot position and the new shoot position at the same time resulting in 2 rays. Sometimes there is a ray that shoots at totally random direction. I have no idea how to fix that.
I am a new developer so please bare with me. If I used this approuch in a multiplayer game, wouldnt I run into trouble if two players used the same gun as they would share the clipsize?
I don't know if you're still answering comments on this video, bit if you do, after the Player gun selector script it gives me an error, the type or namespace name "PlayerIK" could not be found". I've looked in the GitHub that you provided but even with your code it still happened. Help would be appreciated
Seems like you are missing the PlayerIK Script: github.com/llamacademy/scriptable-object-based-guns/blob/main/Assets/Scripts/PlayerIK.cs Cloning the repository fresh I did not get the error. Can you try to make sure you don't have any other compiler errors that prevented it from picking up the script? This is not mandatory and I don't even really recommend to use it in your production game. You can skip all code related to PlayerIK and still have the shooting working. It will just not have the hands tied to the gun.
Hi! I would like to say that this series of tutorials has been very well done and very helpful. And I have a question which is when I implemented this gun system into my project, I found that the trails that shoot out are biased to move upwards and look a bit unnatural in first-person view, is there any way to modify it to make the trail become more straight or fall slowly?
The spread is based on your defined Vector3 (Simple) or Texture. If you feel the "upward spread" is too much, you can play with whichever option you have to lower the variance in that direction. Usually a gun does recoil up, so I would expect that to be one of the primary ways it does recoil 🤔
“Instance” should be capitalized. But for the surface manager, it’s not covered in this video. You can copy/paste the Surface Manager scripts from the repo: github.com/llamacademy/scriptable-object-based-guns/tree/main/Assets/Scripts/Surface%20Manager Or, to understand the implementation you can watch that video: ruclips.net/video/kT2ZxjMuT_4/видео.html
@@LlamAcademy alright one more question, got those errors fixed by going through the impact video, but now i get the error "UnassignedReferenceException: The variable ShootSystem of GunScriptableObject has not been assigned."
Question: I love this implementation of yours because it's very flexible and can be built on top very easily, But I do have a problem. Most games have a gun-changing system or a gun equip system(the one where you can change the gun you are currently using at runtime). However your system doesn't support that, how could I modify it to let me do that? Sorry for the lack of proper punctuation and grammar, English isn't really my primary language.
Swapping active guns may be a good topic to add to the series because it seems to be a highly requested topic. You can do a similar process to what is done in the PlayerGunSelector, or even reuse the logic from Awake when the player presses a button. If you have a game with a layout similar to Counter-Strike where you press 1,2,3,4 to swap weapons, you would just catch the key press, update the "Gun" to whatever is for that key, destroy the old gun, and re-run the Awake logic. Of course it would look better tying in animations, but that concept should get you started!
@@LlamAcademy Thanks for the basic Idea, I'll try to implement it and if you don't mind, may I ask what is the next part after part 6 of the series going to cover?
i'm getting this error in my code in the PlayerGunSelector.cs Severity Code Description Project File Line Suppression State Error CS0246 The type or namespace name 'PlayerIK' could not be found (are you missing a using directive or an assembly reference?) Assembly-CSharp \Unity projects\package creation project\Assets\Guns\Scripts\PlayerGunSelector.cs 13 Active
Hi 👋 You can skip over anything to do with PlayerIK, or you can pull the script off the GitHub repository: github.com/llamacademy/scriptable-object-based-guns/tree/part-1 I mentioned several times in here a better IK will be covered in a future video in this series. This script is pretty basic to just make the demo look okay
There's generally 2 approaches with networked games: 1 do the Raycast on the server based on server-synchronized positions of players / guns and send an RPC/message to clients that the shot was fired from point X to point Y and have the clients only handle the rendering. 2 do the raycast on the client and send a message to the server that it hit something and have the server validate if that's reasonable (that's the hard part 😉- you can skip this but it makes it really easy to cheat). #1 is harder to cheat with, #2 "favors the shooter" which can feel more responsive.
Hi. The surface manager is not covered in this video and can be ignored, or you can watch the video about it to learn more: ruclips.net/video/kT2ZxjMuT_4/видео.html
Thank you for the video! Small bit of feedback the music is a tad loud and it makes it harder to understand you. If anything I'd prefer no music, especially any time there's an editor open. I've had to rewind a good bit 😅
Thank you for the feedback, I thought I had it at a low enough volume to not be distracting but apparently not! I will keep that in mind in the future.
How do games make gun skins? Sometimes, the skins make the gun very different than the original gun. Example: valorant. Skins make guns have different trails, recoil, textures, even different models of the same gun
In the most recent videos in the series, we build out the systems to enable exactly what you're talking about. For a Skin, you can apply the same concept as any other modifier, where it can also apply a different shader or material to the gun.
@@LlamAcademy hi, thanks for your reply. But what about guns that have completely different mesh for skins? Like in valorant, many guns have skin specific components
awesome tutorial man! I've been looking for this exact kinda tutorial since like last week! 😅 Got a noob question for you, Is there a way to apply damage to a gameobject based on where the bullet trail ends up actually hitting? Just trying to see if I can simulate projectile based weapons but with raycasts so players could effectively dodge bullets if they get out of the way of the bullet trail before it makes contact with them? 🤔
You could do something like Physics.OverlapSphere or OverlapBox after the trail reached the target location to be sure the object is still within range of error to count as a hit. Assuming you have fast moving objects, by the time the trail got there the object could have moved too far away to count as hit and you could continue the trail as though it missed altogether
Some of this I have implemented myself, but never before with Scriptable Objects, which sounds like will allow for much more customizability and expandability. Excited for this series!
One of the best things about your tutorials is finding out about new/old things that I never even knew about in all my time of using unity. (case in point, native unity Object Pools?!?!?!?! This is so cool!!!)
This an amazing weapon system, it'll be an amazing starting point to add more advanced stuff like gravity or bouncing
Thanks 🙏! Gravity will come with projectile-based weapons in the future. I covered bouncing bullets before here:
ruclips.net/video/GkStW8-Q5P0/видео.html
I wasn’t planning to cover it in here, but that’s an interesting idea to consider to have it all in one place.
@@LlamAcademy my goal is to add gravity to the raycast, I mean a noob I'll learn a lot if i do it
You can do that, but usually bullets have relatively low mass and high velocity which makes the normal hitscan ray cast “good enough” of a simulation. If you really want to add it, you can follow the concept of this video: ruclips.net/video/8mGZBYsSXcQ/видео.html and it will give you the result you’re looking for.
For those of you wanting to use this for an FPS, configure the player camera to be the raycast start point, from what I've heard making the camera the start point fixes a lot of inconsistencies with aiming
Could you, please, explain how to do it?
@@jesse_belkman too late probs but just switch the camera to that thing
I like how this complex system is organized for a noob that would be frustrated otherwise
Bro, i'm tryna make an fps game, and I haven't been able to find a good video for this kind of stuff for weeks. You, my dear friend, are a god send
You only got 22k subscriber, yes I said ONLY because for tutorials of such quality it's not that much! Keep going!
🧡thank you! I appreciate that!
Hell yeah. This is amazing :D
Once the series is over, something similar for an ability system (think League of Legends for example) would be sick. I've been doing some research lately and there isn't much valuable content about it. Maybe it's a good challenge and opportunity
Anyways, thanks for your awesome work!
❤️!
That’s a great idea! I have a real life use case for that, so maybe once I get some time to play with it and see the challenges I can put together a series on it!
Thanks man! The create tail and render trail funcion and the variabels was very useful for creating the perfect trail. It's always better controlling it with the code. Learnt alot and I could now use this in my own game to create good looking bullets.
Thanks!!!!!!
ive not even finished this series yet and i know its gon be good (everything i need for fps)
so helpful man, thanks for showing the older system too
Great, what a brilliant brain you have to create such sophisticated system and you been so kind to share with us. Thank you a lot mate. You are amazing.
Wow thank you for that! It made me smile 😊
Great content as usual! Looking forward the next videos on this serie! :)
Thanks 🙏 I am too 🙂
The "ParticleSystem" named "ShootSystem", what is it? is it a particle system nested somewhere on the gun prefab? is it for the muzzle flash?
Could you please point me to the video that explains the muzzle flashes and/or the "ShootSystem"?
Thanks in advance for the information.
Found a brief mention of this here:
ruclips.net/video/cI3E7_f74MA/видео.html if anyone is interested...
Hey! The ParticleSystem named ShootSystem is gathered at the time of spawning the gun into the world. I set it up in the code around time 6:20. Around 16:25 I talk about the prefab configuration of the glock and m4. I didn't talk too much about the positioning of it, but you should place it where you want the bullets to spawn, so close to the tip of the muzzle. The assumption here is the muzzle flash and the bullet spawn point can be the same place
In your other comment, in that video we drag references in the Inspector, which I tried to avoid here, instead I'm opting to pick it up automatically on Spawn.
@@LlamAcademy I downloaded your github repo and opened it in the same unity version. Looks like the MuzzleFlash01 is having issues (missing Prefab with guid: numbers-blah-blah. Sadly it keeps me from trying out your system :( ... Thanks for the tuts though, very nice!
@@jeremywieland714 Did you import the Unity Particle Pack after checking out the GitHub?
@@LlamAcademy That was it thanks!
Hi, I am trying to follow this great tutorial, but at 11:34 you use (SurfaceManager) and it is showing up as an error for me. I do not know where in the video this class was created, hope you can get back to me on this. :)
Please see pinned comment
In this video I DO NOT cover the Impact System: ruclips.net/video/kT2ZxjMuT_4/видео.html you can check out that video for the full explanation for how that works!
That’s for the SurfaceManager and ImpactType both. If you’re not interested in using that system for impacts, feel free to just remove that code! Everything will still work!
PlayerIK is a very simple demo script implemented solely for the demo. As I mention in the video, this will be covered in the future, so you can skip that part for now, or check out the project on GitHub to see that naïve implementation.
Edit: Aiming IK is covered in depth here: ruclips.net/video/chgLRjSaoXc/видео.html
where i can get that too? should i download it ? isthere tutorial for it ?
Yes there is a tutorial, that’s linked above. It also has the GitHub repository in the description of the video. This video also has a GitHub repository that includes that code.
@@LlamAcademy OHHH i read ffew times but i cant see git hub thanks man very cool
tysm, i was so worried
Wouldn't the GunType enum prevent you from updating the game over-the-air (like you mentioned in 1:50)? Adding a new gun type would require you to update the code and thus require a new build. Since you're using it as a unique identifier, a string or integer might be a better fit. Just need to remind the designer to make the identifiers unique (or write an editor script to automatically fix them).
Otherwise pretty great tutorial. Straight to the point and very little to no fluff.
Yes you are correct! In the final section I discuss ways to solve that problem. Specifically, I talk about how you could use the "Name" parameter on the GunScriptableObject to match against in place of GunType.
Edit for some more context:
For most developers, that's not going to be within the scope of what they'll implement. Typically I don't like "magic strings" that have significant meaning, so I implemented the GunType to have a declarative way to match the guns for the majority of users, and in the end of the video I talk about how you can support the over the air updates by using the Name as a "magic string"
@@LlamAcademy Alright I missed that part.
The real solution to avoid magic strings would be to have an editor tool that automatically populates the identifiers with Guid or something similar but that's way out of this video's scope.
Might be an interesting topic in the future though. I feel like editor scripting in general is not discussed a lot.
Broooo you made my hand and fingers pain by writing that much code for the first time 😅
In GunScriptableObject.cs, why is the TriangleIndex set to 0 directly in the following line?
SurfaceManager.Instance.HandleImpact(
HitCollider.gameObject,
HitLocation,
HitNormal,
ImpactType,
0
);
Won't this result in incorrect impact results if there are multiple submeshes?
So looking forward to this series !!!
Me too 😁! This is one topic area I feel is underserved and needed!
21:00 so my question here is, I've tried putting assets in the Resources Folder before, and then created a folder hierarchy within it, and couldn't reach the hierarchy. What do I need to do to reach the hierarchy or is that what addressable resolves? This is effectively my second week in Unity and I am trying to learn C# principles as well as how Unity functions, so forgive me if this question is obvious, or incomplete.
For resources folder you can load with the path name to the file without “Resources”. Resources are bundled on build, so if you include everything there, you can easily reference them. Addressables allow you to extend the game without needing to rebuild the whole game.
@@LlamAcademy awesome, I saw some videos, that were not beginner level, and it seemed like that was the next step in my programming journey after the basics! Thanks for confirming that!
hey amazing video and i have followed but i have a problem, when i click "create
Usually that’s because the gun scriptable object was not converted from “: MonoBehaviour” to “: ScriptableObject” or the [CreateAssetMenu] tag is missing, or improperly defined (such as copy/paste issue with multiple SO with the same path)
@@LlamAcademy i did everything correct as you said but still doesnt work i grabbed the code from your github so its copy pasted, i dont know what to do now, if you are ok on communicating on discord so i can show you a picture of the error. it would be the easiest method.
Okay. Send me a message llamasoftware#5070
@@LlamAcademy Hi, what was the issue on this one?
oh, found it.
Hey Chris, how do you plan these Systems? This Guide is honestly pretty damn good. Do you just start by coding some of the ideas until you have a working prototype or do you plan these systems upfront and if so got any tips on how to design systems?
My planning for systems is probably not the ideal model.
I typically think about things for...between seconds to minutes then get started working on it from basically just the "idea". Usually it works out okay, but there are some holes or problems that I refactor as I run into the limitations of whatever the initial design was.
For this system I had already done that full process of design, implementing, & refactoring in my old (now unpublished) mobile game Llama Survival. I had already identified a bunch of the problems & solutions that I couldn't or wouldn't solve in the first implementation for that game, and that was the starting point for this tutorial series.
I think what works best for you really depends on whether you like to plan all the details out ahead of time, or you like to just get into the weeds and figure it out. The latter has a higher risk of rework and the first iteration usually has some problems. I just like to just get started on things 😅. That's more rewarding for me than spending a ton of time on the initial design.
@@LlamAcademy Thanks for the insights.
Yeah what I've found to be working quite good is a mix of both. Just thinking about what I need on a high level and then get right to work. When I feel like I'm stuck I iterate on my design and try to fix things on paper before I code again. When I just code before having a high level overview that's usually when shit starts to blow up for me 😅
I have a question. Maybe someone can help me. But first a big thank you for the great tutorial! The raycast is performed at the beginning of the shot. How is it supposed to catch an moving object like an enemy which is at that point not in line with the raycast?
When using a Raycast you perform all the hit detection on the frame you click, everything after that is just VFX that happens after the fact to show the player something is happening :) If you shot them where they were that frame, it should all be good. If not, then you missed!
Hello! I have a little issue with trails, i tried to apply your system in my fps project, and it mostly works, but i can't see the bullet trails in game mode. Through editor i can see that they're actually going out of my gun(not the actual trails, but the objects, when i select them in editor) in right direction(i think it happens because i use 2 cameras, 1 of it actually renders weapon and all its children in overlay. But i have a problem with muzzleflash's child in weapon prefab, its not applying to layer for player weapon, that might be the issue, but i am still not sure).
Sorry if my comment seems incorrect, English is not my native language.
I'm still looking for a solution, but as far as I can tell, the problem is not related to layers and cameras, because no matter what layer is selected, objects in it are always rendered except bullet trails
you are awesome ,please keep the brilliant work❤❤
In the GunSo you have ImpactType and SurfaceManager, which appear to not be a part of the unity engine. where did you make those or get those classes/objects from?
Same with PlayerIK in PlayerGunSelector
👋 Hi! PlayerGunSelector we implemented in this video. When I talk about SurfaceManager / ImpactType I mentioned it was covered in another video (that’s linked in the description). The full project is on GitHub so you can view all those files. A better version of the PlayerIK will be done in a future video. As I said, It was really just for the demo to look nicer with the hands actually on the gun
I don't think that you're going to see this, but if you did, how did you fix this?
@@joaodias8824 sadly I never fixed it
@@kamron4825 if I figure it out I'll let you know
Hello. As I said above you can find the SurfaceManager and ImpactType on the GitHub github.com/llamacademy/scriptable-object-based-guns/tree/main/Assets/Scripts/Surface%20Manager
If you would like to understand how those are created, you can check out the associated tutorial: ruclips.net/video/kT2ZxjMuT_4/видео.html
These can be completely skipped and ignored if you do not want to use that impact system without any additional loss in functionality.
PlayerIK is also in the repository: github.com/llamacademy/scriptable-object-based-guns/blob/main/Assets/Scripts/PlayerIK.cs, but again I don’t recommend relying on this because I just quickly put it together without much thought. Later in the series we’ll probably review a better implementation.
In this video I covered PlayerGunSelector at 13:00. You can always check the chapters at the bottom of the video to see each section.
Having 'LastShootTime' in the SO itself, won't that cause problems when there are multiple instances of 'PlayerGunSelector'?
For eg:- Let's say we use this system to equip enemies with weapons and there are multiple enemies with M4, but there is only on 'GunScriptableObject' of M4. Won't changing the 'LastShootTime' for one enemy change it for all enemies?
or even in a multiplayer scenario, won't it cause a problem?
Good question. In this video we didn't get into solving that problem, but you are right you will need to clone the SO or create instances to be used at runtime. Later on in the series we tackle that.
@@LlamAcademy oh that's nice. I didn't check the whole series as I just wanted to check the design pattern (even tho I have watched this video several times, i keep coming back. lol). Seems like I should put in proper time to watch the whole series.
Great stuff as always!
Much appreciated 🙏
tryed to put bullet prefab in but it wont let me
help
Did you assign the bullet script to your prefab?
Thanks for this dude!
why wont my private ObjectPool TrailPool; work
this is the error Assets\Scriptys\GunScriptableObject.cs(21,13): error CS0246: The type or namespace name 'ObjectPool' could not be found (are you missing a using directive or an assembly reference?)
pls help🤔
Which version of Unity are you on? The object pooling API was introduce in the 2021 LTS.
You need to stop doing everything uprfront. It is soo hard to figure out what is actually happening when you just spend 10 mins rattling off a bunch of code. Make it by following the logic of the functionality instead of setup then implementation. Start with a basic implementation and then add complexity on top of that. You might as well just have people download the files because this isn't really teaching the concepts from the ground up it is just rote memorization of how to do a very specific type of thing.
I agree with you about this 😢
Amazing! | Just asking if you have any tutorial to zoom in with the gun? If you do please reply to me.
I do not but that is on my list for this series
How can I application quit in build I know the editorial application quit application.quit() in build not working
Hi great tuturial ! which part do you show how to set up the IK script or do you have a seperate tuturial🙂
I do not have the IK tutorial yet, but you can check out the project from GitHub and review this implementation as a quick and dirty get started point!
@@LlamAcademy Brilliant thank you very much 🙂
I don't know how to fix that problem... Can anybody help?
GunScriptableObject.cs(9,9): error CS0246: The type or namespace name 'ImpactType' could not be found (are you missing a using directive or an assembly reference?)
PlayerGunSelector.cs(16,10): error CS0246: The type or namespace name 'PlayerIK' could not be found (are you missing a using directive or an assembly reference?)
Hi 👋. The impact system won’t be covered in this series because it was covered in this video: ruclips.net/video/kT2ZxjMuT_4/видео.html The full projects for all my videos are available on GitHub, so you can download those scripts from here: github.com/llamacademy/scriptable-object-based-guns (links also in description). Since this video is part 1 only, you may change the branch to “part-1” to only see what you see here.
Good luck!
Hey LlamAcademy, i love your video. however i have one small issue when adding public ImpactType ImpacType; i get the error CS0246: The type or namespace name 'ImpactType' could not be found (are you missing a using directive or an assembly reference?). is surface manger a addon i need to add to my unity project???
Check out pinned comment & description!
Hi! thank you for this tutorial. I'm a newbie in unity coding so I followed each script closely but somehow still cant get the create -> guns menu show up on my end. I tried looking at the scripts from your github but it seems it's a more refined version of the scripts for later part of this tutorial series.. There's an error log saying "failed to find entry-points" with long logs under it (which I don't understand) If anyone encounter the same problem or have an idea on its solution, please help ;-;
Update: I solved it but I have a question about the PlayerIK script as it won't show up on the inspector and gives error logs... please help ;-;
Great series. Learning a lot about scriptable objects. I do have one question however. In the repository there are a number of "Editor" scripts that aren't explained in the video and it appears the SO scripts won't function without them?
thx
You do not NEED any of the editor scripts for them to work, but they make it easier, faster, and more convenient to set stuff up. How the custom inspectors are done are covered in these: ruclips.net/video/3w9iXT6wx5g/видео.html & ruclips.net/video/moXvNj7QUHE/видео.html
Each video in this series has its own branch in the github repository so if you want to see just what was done in video 1, check out branch "part-1"
I couldn't finish my code relying this turorial, but thanks, it's really cool video. I faced mistake when I tried make ObjectPool(CreateTrail) - now we need to provide a second argument "actionOnRelease". I can approximately imagine how to do it, but anyway it's a bit complicated to me).
Hmm... the 2021 Object Pooling system should not require you provide the secondary argument. If you want to understand more about the 2021 Object Pooling system you can check out my full tutorial on that: ruclips.net/video/zyzqA_CPz2E/видео.html
For any shooting system, I highly recommend using an Object Pool to eliminate garbage and keep your game running smoothly
@@LlamAcademy Thank you for your answer! I know that I need to dig deeper. I'll definitely check it out to fully understand this topic.
the problem i am having is i am having a virtual camera that follows character positioned at characters back....show only characterss back portion will show now during swipe code of look functionality of starter asset its rotating in every angle so may characters side and front portion is visisble ...is it possible that any swiping character also rotate on camera direction...so only back portion of character will be seen..please help
I have a two errors
Assets\Scripts\Gun\PlayerGunSelector.cs(15,12): error CS0246: The type or namespace name 'PlayerIK' could not be found (are you missing a using directive or an assembly reference?)
&
Assets\Scripts\Gun\PlayerGunSelector.cs(15,12): error CS0246: The type or namespace name 'PlayerIK' could not be found (are you missing a using directive or an assembly reference?)
can some help plz
Other than that its a good tutorial
Please see top of description
11:38 I don’t have the surface manager nor the impact type
Hi. There’s several comments around this one. In this video I DO NOT cover the Impact System: ruclips.net/video/kT2ZxjMuT_4/видео.html you can check out that video for the full explanation for how that works.
In there we create the SurfaceManager and ImpactType. If you don’t care yet about impact effects, you can safely skip those and you will still be fine 💪
@@LlamAcademy yeah just saw that😅 great vid very good system
Ive finished the code, im having trouble with line 42 of gunscriptableobject shoot() saying object refernce nnot set to an instance of an object. i need help :(
Do you have a particle system as a child of the gun?
I have the same issue ;-;
trails is creating nicely but they are created far from pistol,,,,not from the pistol...is there any solution?
Are you assigning their start position to the gun particle system as soon as you spawn them?
i know this is a relatively old video but i wonder how can i change so instead of using the GunType enum to hold different guns, instead serve as a way to differentiate shooting modes, something like:
enum GunType{
SemiAutomatic,
Automatic,
Burst
}
I think i should have different Shoot functions and use a Switch to select the shooting mode depending on what GunType the Gun is assigned to, but i'm afraid that having 3 functions with almost identical code is a bad way to do this, so i don't know how to approach this
In my game to differentiate between burst and automatic I applied a modifier to the gun to adjust the mode, "number of bullets per shot", and increased the delay between shots by 3x. In the "Shoot" function all I did was check if it was "burst" and started a coroutine to spawn 3 bullets over the course of several frames instead of 1 in a single frame. The outcome is minimal changes to "Shoot" and the rest of the gun system remained unchanged. Later on in this Gun Series I cover a modifier and attachment system that can help achieve this effect (around part 9 & 10).
I didn't do Semi-Auto in my game, but I think that is possible to handle by just tracking if the player has at least 1 frame where they were not pressing "shoot" then proceed with the current code flow
Does the weapon work well for FPS? Or adjustments have to be made. Thanks for making such a complete tutorial.
Yeah it should work for FPS. I saw a few people are using it in FPS scenarios successfully
can some one help me?
in 11:30 he use SurfaceManager by mine script dont work
The SurfaceManager is done in another video, linked in description. You can skip that if you do not need impact effects at this time.
Hi, I think the system is not that extensible, the gunSO would not work as expected because only one of its kind is allowed to spawned in the scene, what if your enemies also have that same gunSO ?
We are cloning the SO so each individual user of a gun has their own instance of a gunSO that can be configured as needed
@@LlamAcademy Hi Chris, thanks for your answer, just to clarify, to clone the SO we have to change from this
- gunSO = guns.find(...);
- gunSO.Spawn(...)
to this ?
- gunSO = guns.find(...);
- newGunSO = Instantitate(gunSO)
- newGunSO.Spawn(....)
Sorry. I don't think in this video we got into cloning the SOs in this video. Yes, you will need to do something like that.
I don't remember the exact video but later on in this series we get into that, probably when we get into modifiers/attachments.
@@LlamAcademy Many thanks, good day!
Do you have a weapon manager video? I don't think there exists one on youtube. For choosing and equiping a weapon before the match starts, or as we spawn like in Valorant.
I’m thinking that in this series I may cover some kind of gun selector!
I have an issue when im firing the trail is instantiation from the ground
Make sure you have the particle system at the tip of the gun and when you are spawning the bullet to set the spawn point to be at the same point!
@@LlamAcademy yea thanks I fixed
Are you using the Unity Third person controller along side this?
Yes that is the base for the movement and the model
Hey, thank you for the tutorial, I am new to unity and have tried to follow this for a couple of hours but have hit an issue, I'm not sure if it's due to me not using your SurfaceManager and Impact Manger, I have followed along and typed the code out exactly although I'm receiving this error while attempting to fire;
NullReferenceException: Object reference not set to an instance of an object
GunScriptableObject.Shoot () (at Assets/Scripts/Weapons/GunScriptableObject.cs:39)
PlayerAction.Update () (at Assets/Scripts/Weapons/PlayerAction.cs:12)
I've since tried copying your code from github and replacing the 6 files creating in this tutorial but I had the exact same error so I think I have missed something in the setup in Unity but I'm at a loss as to what if you have any advice I'd appreciate it.
I've also tried importing Unitys particle system as recommended to another commenter but it didn't change anything.
Can you give me the code at line #39 of GunScriptableObject.cs? From the repository on part 1 that is not a line that can give any error.
If it is:
Vector3 shootDirection = ShootSystem.transform.forward + ....
It is important that your Gun model has a Particle System as a child of it and is positioned at the tip of the barrel. This is where all bullets will spawn. If you do not do this, ShootSystem will be NULL and give you that error. We assign ShootSystem on Setup() by doing: ShootSystem = Model.GetComponentInChildren();
which requires that the Particle System is a child of the instantiated gun prefab model.
Let me know if you run into any issues after doing that!
Does this project differentiate which kind of interaction to use for which weapon? Like how a glock is semi, an m4 is automatic, a laser gun is charge/release
Not really. The gun system supports any of these, but the player interaction with the gun system is left to the implementer. If you would like these “fire mode”s I’d recommend to add that to the ShootConfigSO and read it on your “PlayerInput” and use that to determine if the gun.tick() should be called
beam trails will work with this type of system or will it need additional programming?
Depends on how you want to do the beam I suppose
I also still have playtrail does not exist in the current context should that still be there
So if I not implement the part with the Surface Manager (the vid in the info) i have no visuals… so I have to watch the video and implement the surface manager etc right?
You will not have impact effects, but you can also just pull the surface manager off GitHub. It’s included in this repository as well as the dedicated surface manager video repository.
Thanks a lot
( this shouldn't be a link
Awesome tutorial! Quick question, I've used the system for a RTS game, but I can't seem to figure out why does the duplicated unit detects an enemy, the original shoots. Any thoughts? Thanks in advance!
Sounds like maybe the ScriptableObjects aren't cloned properly and all are using the original?
I'm getting this error:
" NullReferenceException: Object reference not set to an instance of an object
at UnityEngine.Rendering.Universal.UniversalRenderPipeline.SetupPerFrameShaderConstants () [0x00089] in :0
at UnityEngine.Rendering.Universal.UniversalRenderPipeline.Render (UnityEngine.Rendering.ScriptableRenderContext renderContext, System.Collections.Generic.List`1[T] cameras) [0x00065] in :0
at UnityEngine.Rendering.RenderPipeline.InternalRender (UnityEngine.Rendering.ScriptableRenderContext context, System.Collections.Generic.List`1[T] cameras) [0x0001c] in :0
at UnityEngine.Rendering.RenderPipelineManager.DoRenderLoop_Internal (UnityEngine.Rendering.RenderPipelineAsset pipe, System.IntPtr loopPtr, UnityEngine.Object renderRequest) [0x00046] in :0 "
when i'm playing on build
This seems like it an error related to URP 🤔 not sure
this work well can we do this for mele combat swords and hand
is it possible to do trail without object pooling because i am in 2020 and i cannot access unity object pool
I would really recommend to use some form of object pool for this. In my earlier videos when 2021 wasn't out I made a simple one you can use (video: ruclips.net/video/fsDE_mO4RZM/видео.html code: gist.github.com/llamacademy/e3ed9e647b2c703d698a809d00a112a8 )
If you don't want to, you can use Instantiate/Destroy instead of getting objects from the pool and disabling them.
Hello, does anyone know in what video does he implement the IKs for the gun holding animations? Thanks in advance!
#12 Aiming with Inverse Kinematics (IK) and Animation Rigging | Gun Series 12 | Unity Tutorial
ruclips.net/video/chgLRjSaoXc/видео.html
@@LlamAcademy thank you, good sir! Have a nice day!!!
I decided to cut out InverseKinematics since i'm using Unity Personal, so i really can't do it.
If there is a workaround, please tell thee.
There's no limits to functionality within Unity. You can be on Personal and still use this fully.
the Object pool keeps showing this error: "The type or namespace name 'ObjectPool' could not be found (are you missing a using directive or an assembly reference?)"
We’re using the Unity 2021 object pooling system here. As long as you are on 2021 LTS or higher you should be able to add “using UnityEngine.Pool;” at the top of the script and it should work for you.
Awsome but were I find the tutoria to make the StarterAsset as a Third Person Shooter? 😅😅
does someone know where can i get the IK and the doll that he is using in this video?
Please see top of the description
@@LlamAcademy i see it, thanks , btw im having a mistake with the prefabs, MuzzleFlash01 is missing, the model suposse to have it right? i download the github`s First version but is has the same problem
I`v seen the read me doc and i could fix that problem, but still li light is pink, and i dont know where to get other particle to switch
When i try to change active gun while game is running it says "The variable ShootSystem of GunScriptableObject doesn't exist anymore." what can i do to change my gun while game is running
That's a more complex answer than I can probably reasonably do in a comment. I am planning on adding a video in the series about weapon swapping because that is a very commonly requested topic!
I am getting errors saying
Assets\GunScriptableObjects.cs(135,50): error CS1002: ; expected
Assets\GunScriptableObjects.cs(119,15): error CS1513: } expected
Assets\GunScriptableObjects.cs(119,15): error CS1002 ; expected
Assets\GunScriptableObjects.cs(52,48): error CS1001: identifier expected
Can you put the scripts in a GitHub, or type it in the Description because i have no idea what this means :/
It is on GitHub and the link is in the description
I don't know how to fix the problem. Please somebody help me
Null reference not set to an instance of an object
GunScriptableObject.Shoot().cs:246
Hmm… from this video GunScriptableObject does not have 246 lines of code. Can you please review your implementation compared to the part-1 branch? github.com/llamacademy/scriptable-object-based-guns/blob/part-1/Assets/Scripts/Gun/GunScriptableObject.cs
Mr. Chris sorry to bother you but where on github can I download all the most recent scripts for this shooting project. I thought I downloaded all the scripts but the code has errors in surface manager and a few other places
Hi! If you download the project from github.com/llamacademy/scriptable-object-based-guns and follow the setup instructions there (downloading Unity Particle Pack for example) it should work with no errors.
Each video has a branch with exactly what you saw on that video. For this one, at the top left where you see a dropdown that says "main" you can change that to "part-1" and it will reflect exactly where this video ended.
If you download the latest "main" and it has some errors, can you share those exact error messages along with your version of Unity so I can troubleshoot those? It should be very easy to get working.
@@LlamAcademy Thank you for your help that worked.
I did the same thing you did in the video, but it didn't work, only the gun was on the player's body. I deleted them with impcat type , player ik or something . Can you post the player ik script file? and can you solve this problem of mine please because we will enter the game contest
The full project is on GitHub. You can check out the whole thing working together. Link’s. In the description
Hello, I am having an error with this line of code
remainingDistance -= TrailConfig.SimulationSpeed * Time.deltaTime;
It says that TrailConfigurationScriptableObject does not contain a definition for SimulationSpeed. Is there any import or something that i missed? Any ideas of how to fix this?
Seems like on the trail config you missed a step. Double check that section and what you have defined versus what is in the GitHub repository: github.com/llamacademy/scriptable-object-based-guns/tree/part-1
Awesome video! Just wish explanation would be little bit slower. My brain had to switch to second gear to keep with the pace of video. Other than that great job!
It's always a fine line to walk between "too fast" and "quit droning on and on". I'm generally a fast paced person so I guess it comes through in the videos sometimes 😅
Hi, i'm getting this error "MissingReferenceException: The variable shootSystem of SO_Gun doesn't exist anymore." after a few seconds on play mode, but i don't know how to fix it, somebody can healp me?
Sounds like maybe your gun prefab doesn't have a Particle System as a child of it
@@LlamAcademy thx for the fast answer, the problem was that i has the particle system, but my dumb-ass did not called it in the gun script…thx again
Hi, I'm using your ScriptableObjectBased Gun System on FPS game.
When I walk and shoot at the same time, the bullet trail came from behind the gun(kind of behind camera).
I tried to fix it by changing the startPosition of Trail at the begginingof the BulletTrail Coroutine, but it was same result.
And also, when walk left, walk right and shoot at the same time, bullet trail start from air too,
Do you have any idea how to prevent from happening these.
Thank you for your great tutorial.
Hey! I think someone else asked about that in the comments of one of the videos, but I can't seem to find it now.
In most games, this "problem" exists because the player and the gun are moving. Even though we spawn correctly from the barrel of the gun, that was at a snapshot in time.
I looked into several other AAA games to see if this was something of an oversight that I had or what the deal was. It turns out even AAA games either: have this problem, or mitigate it by having extremely short bullet trails.
The solutions I see are:
1. Leave it alone and have this "problem" - it can be mitigated somewhat by having smoke or something that comes out of the barrel afterwards to mask the effect.
2. Have very short lived bullet trails - player can't see the "problem"
3. Bind the start position constantly to the barrel of the gun (this results in "bending" of the trail which may not be desirable).
Hey what is this SurfaceManager ? I dont have that ..
It's how we manage impact effects. That was covered in a separate video and has a dedicated github repo. More details in description and the pinned comment.
Hey @LlamAcademy I was hoping to get the github version of this project working, as it was awesome to see it graciously provided and I was looking to compare my current system which has been built upon from your previous tutorials. I just had one problem, it doesn't seem to be explained how I go about importing Unity Particle Pack into the project without destroying the settings. Also awesome production quality on these videos B)
Hi! Great question, and a common one. The Unity particle pack can be imported without overriding settings if you deselect all of the project settings files (they’re like the last ones). If you only select the folder about Effect Examples you will only get the particle systems, materials, and textures
@@LlamAcademy Thanks for the quick reply! Got it working great now as long as the hilarious aiming isn't caused by me, I could see this whole looking down+aim bull in a china shop movement mode working quite well if implemented as a feature XD CHARRRGE hahaga. As it's a common question it could be nice to have a quick explanation added to the github's "Quickstart", including updating materials. Looking forward to seeing how far this series goes!
😁 the movement and aiming is not particularly well implemented. It was a quick hack job just to get something there while we implemented the core “gun functionality”. Coming soon - accurate crosshairs! Movement still will be crazy while aiming but the aim will be right.
Sorry! I meant to say as well, I will update the readme with that info!
Hey one question which Third Person Controller Asset do u use ?
I use the Unity Starter Assets Third Person Controller assetstore.unity.com/packages/essentials/starter-assets-third-person-character-controller-urp-196526 It's free!
Hey! This tutorial looks great, but when I download it from Github, it keeps giving me errors. I think the issue is with the MuzzleFlash particle system in the gun previews
Did you import the Unity Particle Pack after cloning from GitHub?
@@LlamAcademy Yeah, but they don't work with URP
Edit: the render pipeline converter solves the issue
@bbrainstormer2036 awesome to hear!
Yo I added the trail but sometimes the trail for a bullet will just shoot off to the side and stretch out, is there any way to fix this?
Hmm.... usually the only way I can get that to happen is if I don't wait a frame before reactivating the TrailRenderer. Can you compare what you have to what is on Github: github.com/llamacademy/scriptable-object-based-guns/tree/part-1 ? And if you get the same behavior with that, show me a short video of what is happening and what configuration you are using?
@@LlamAcademy I'm having this same issue, the trail shoots to the last shot position and the new shoot position at the same time resulting in 2 rays. Sometimes there is a ray that shoots at totally random direction. I have no idea how to fix that.
instance.transform.position = StartPoint; I was missing this line
I am a new developer so please bare with me.
If I used this approuch in a multiplayer game, wouldnt I run into trouble if two players used the same gun as they would share the clipsize?
No, there would not be an issue there. Each player would have their own copy of the ScriptableObject that is being manipulated in that case!
I don't know if you're still answering comments on this video, bit if you do, after the Player gun selector script it gives me an error, the type or namespace name "PlayerIK" could not be found". I've looked in the GitHub that you provided but even with your code it still happened. Help would be appreciated
Seems like you are missing the PlayerIK Script: github.com/llamacademy/scriptable-object-based-guns/blob/main/Assets/Scripts/PlayerIK.cs
Cloning the repository fresh I did not get the error. Can you try to make sure you don't have any other compiler errors that prevented it from picking up the script?
This is not mandatory and I don't even really recommend to use it in your production game. You can skip all code related to PlayerIK and still have the shooting working. It will just not have the hands tied to the gun.
@@LlamAcademy Thanks, I'll test it out
Hi! I would like to say that this series of tutorials has been very well done and very helpful. And I have a question which is when I implemented this gun system into my project, I found that the trails that shoot out are biased to move upwards and look a bit unnatural in first-person view, is there any way to modify it to make the trail become more straight or fall slowly?
The spread is based on your defined Vector3 (Simple) or Texture. If you feel the "upward spread" is too much, you can play with whichever option you have to lower the variance in that direction.
Usually a gun does recoil up, so I would expect that to be one of the primary ways it does recoil 🤔
I keep getting errors saying "The name 'instance' does not exist in the current context" did I miss something?
“Instance” should be capitalized. But for the surface manager, it’s not covered in this video. You can copy/paste the Surface Manager scripts from the repo: github.com/llamacademy/scriptable-object-based-guns/tree/main/Assets/Scripts/Surface%20Manager
Or, to understand the implementation you can watch that video: ruclips.net/video/kT2ZxjMuT_4/видео.html
@@LlamAcademy alright, thank you! I just kind of assumed such a generic word like Instance would already be used by unity!
@@LlamAcademy alright one more question, got those errors fixed by going through the impact video, but now i get the error "UnassignedReferenceException: The variable ShootSystem of GunScriptableObject has not been assigned."
does anyone know how to fix surfacemanager error ? , it would really helpfull
Please check pinned comment
Very Modularity, I like it.😂
Question: I love this implementation of yours because it's very flexible and can be built on top very easily, But I do have a problem. Most games have a gun-changing system or a gun equip system(the one where you can change the gun you are currently using at runtime). However your system doesn't support that, how could I modify it to let me do that? Sorry for the lack of proper punctuation and grammar, English isn't really my primary language.
Swapping active guns may be a good topic to add to the series because it seems to be a highly requested topic. You can do a similar process to what is done in the PlayerGunSelector, or even reuse the logic from Awake when the player presses a button. If you have a game with a layout similar to Counter-Strike where you press 1,2,3,4 to swap weapons, you would just catch the key press, update the "Gun" to whatever is for that key, destroy the old gun, and re-run the Awake logic. Of course it would look better tying in animations, but that concept should get you started!
@@LlamAcademy Thanks for the basic Idea, I'll try to implement it and if you don't mind, may I ask what is the next part after part 6 of the series going to cover?
Anybody else having some trouble with "The type or namespace name 'PlayerIK' & 'ImpactType' & 'SurfaceManager' could not be found"?
Yes. Please see pinned comment
i'm getting this error in my code in the PlayerGunSelector.cs
Severity Code Description Project File Line Suppression State
Error CS0246 The type or namespace name 'PlayerIK' could not be found (are you missing a using directive or an assembly reference?) Assembly-CSharp \Unity projects\package creation project\Assets\Guns\Scripts\PlayerGunSelector.cs 13 Active
Hi 👋 You can skip over anything to do with PlayerIK, or you can pull the script off the GitHub repository: github.com/llamacademy/scriptable-object-based-guns/tree/part-1 I mentioned several times in here a better IK will be covered in a future video in this series. This script is pretty basic to just make the demo look okay
Can i transform this to use it for a doom clone game?
I don’t see why not 🙂
What do i do to get the surface manager?
You can check it out from this project or the dedicated Surface Manager github. Those are all linked in the description.
ok thanks@@LlamAcademy
wb knife throwing projectile?
You could probably handle that here as well with a low rate of fire and customized animation. Projectiles are covered in Part 6 of this series!
I want to do this with netCode... I didn't find anything about it...
There's generally 2 approaches with networked games:
1 do the Raycast on the server based on server-synchronized positions of players / guns and send an RPC/message to clients that the shot was fired from point X to point Y and have the clients only handle the rendering.
2 do the raycast on the client and send a message to the server that it hit something and have the server validate if that's reasonable (that's the hard part 😉- you can skip this but it makes it really easy to cheat).
#1 is harder to cheat with, #2 "favors the shooter" which can feel more responsive.
@@LlamAcademy grateful
What just happend. 😭Im learning C# for about under a year now ... what must i do to become so heckin' good like you! Im amazed, honestly.
😅 thank you for the compliment. Just keep working, practicing, and learning. You will get better!
I keep getting error on the surface manager script
Hi. The surface manager is not covered in this video and can be ignored, or you can watch the video about it to learn more:
ruclips.net/video/kT2ZxjMuT_4/видео.html
Thank you for the video! Small bit of feedback the music is a tad loud and it makes it harder to understand you. If anything I'd prefer no music, especially any time there's an editor open. I've had to rewind a good bit 😅
Thank you for the feedback, I thought I had it at a low enough volume to not be distracting but apparently not! I will keep that in mind in the future.
@@LlamAcademy Appreciate you hearing me out!
How do games make gun skins? Sometimes, the skins make the gun very different than the original gun. Example: valorant. Skins make guns have different trails, recoil, textures, even different models of the same gun
In the most recent videos in the series, we build out the systems to enable exactly what you're talking about. For a Skin, you can apply the same concept as any other modifier, where it can also apply a different shader or material to the gun.
@@LlamAcademy hi, thanks for your reply. But what about guns that have completely different mesh for skins? Like in valorant, many guns have skin specific components
Sounds likely they just have a different prefab with the same base model and each skin can have fancy other attachments or different materials
Yor GitHub code of ShootConfigScriptableObject give me errors :(
Can you open an issue on GitHub with the errors you are getting?
@@LlamAcademyDon't worry I fixed it, thank u
awesome tutorial man! I've been looking for this exact kinda tutorial since like last week! 😅
Got a noob question for you, Is there a way to apply damage to a gameobject based on where the bullet trail ends up actually hitting? Just trying to see if I can simulate projectile based weapons but with raycasts so players could effectively dodge bullets if they get out of the way of the bullet trail before it makes contact with them? 🤔
You could do something like Physics.OverlapSphere or OverlapBox after the trail reached the target location to be sure the object is still within range of error to count as a hit. Assuming you have fast moving objects, by the time the trail got there the object could have moved too far away to count as hit and you could continue the trail as though it missed altogether