Announcement

Collapse
No announcement yet.

Working on my first Weapon Blue Print System. I Hit a Wall

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

    Working on my first Weapon Blue Print System. I Hit a Wall

    Hello everyone!

    I'm working on my first weapon BP. I have been reading whatever I could get my hands on, trying to figure out the best, Newb friendly way to go about this. I opted to go with a Gun Parent. From that I created two Children which have different fire rates and ammo counts. Nothing too crazy. But then I wanted to add in a Line Trace as I plan to make a Laser at some point. From what I understand I'm supposed to add the Line Tracer into my Parent BP. Is that correct?

    I attached a few photos. "Default Projectile" was my base projectile across my weapons. I then went and created the Line Tracer in the Gun_Parent BP right above it. But then I hit a wall. I have two separate weapon systems at this point a Projectile and a Line. How do I choose which which to fire and when? As of right now I have to take the Fire Bullet and either attach it to one or the other. How do I configure this BP so that I can fire either one? I was thinking of using a Branch to connect them but it always calls to the Trace. I hope I'm making sense. If not I apologize in advance and thank you for your help!
    Line part 2 Main Projectile Line

    #2
    Hiya, did you solve this? If not: yeah you could use a branch, but better yet: setup an enum called something like firetype, guntype or .... List all the firing types you want. Then use the enum to switch between linetrace or projectile. Include it in your base weap BP. Then use switch on E_"firetype" to make you weap fire off what you like. Set the "firetype" enum on the weapon whenever you change ammo or however you want. I have attached a real quick slap together just to give an idea. You can have as many different firetypes or Modes (single, burst, continous) as you like using the same method.

    Comment


      #3
      Originally posted by Neira View Post
      Hiya, did you solve this? If not: yeah you could use a branch, but better yet: setup an enum called something like firetype, guntype or .... List all the firing types you want. Then use the enum to switch between linetrace or projectile. Include it in your base weap BP. Then use switch on E_"firetype" to make you weap fire off what you like. Set the "firetype" enum on the weapon whenever you change ammo or however you want. I have attached a real quick slap together just to give an idea. You can have as many different firetypes or Modes (single, burst, continous) as you like using the same method.

      Neira,

      Thank you for taking the time to respond. I've been stuck on this for a few days now. I'll look into Enum's (this will be my first time using them).

      Comment


        #4
        Originally posted by inaudiblefuzz View Post


        Neira,

        Thank you for taking the time to respond. I've been stuck on this for a few days now. I'll look into Enum's (this will be my first time using them).
        np, Lmk how you get on/ if you need more help. You've got me wanting to start a new project. Enums, are great to use when you get your head around them. Once you set your enum up, you could put it in your parent ammo class aswell. That way, when you run over your ammo pickup, or drag/drop your ammo onto your weapon in inventory, you can set the weapon enum from the pickup class and it would fire how you want it to.

        Comment


          #5
          Originally posted by Neira View Post

          np, Lmk how you get on/ if you need more help. You've got me wanting to start a new project. Enums, are great to use when you get your head around them. Once you set your enum up, you could put it in your parent ammo class aswell. That way, when you run over your ammo pickup, or drag/drop your ammo onto your weapon in inventory, you can set the weapon enum from the pickup class and it would fire how you want it to.
          I'm just following along to some general tutorials trying to get a better understanding of BP's. I am stuck on the weapon system. The info's there I just can't piece it together. : /

          Comment


            #6
            Originally posted by Neira View Post

            np, Lmk how you get on/ if you need more help. You've got me wanting to start a new project. Enums, are great to use when you get your head around them. Once you set your enum up, you could put it in your parent ammo class aswell. That way, when you run over your ammo pickup, or drag/drop your ammo onto your weapon in inventory, you can set the weapon enum from the pickup class and it would fire how you want it to.
            Any chance you would be free to work one a BP together, sometime? I'm still lost.

            Comment


              #7
              Originally posted by inaudiblefuzz View Post

              Any chance you would be free to work one a BP together, sometime? I'm still lost.
              I might be able to put together a quick/small fps project with a weapon that can switch between linetrace fire and projectile, and up it to github. I will just use the fps project in 4.21 with no starter content. I can comment all the Blueprints in the weapon class and Ammo pickup so you can follow along with what I did. School is back in for me in 2 days, So I will be quite busy for a bit, but ill be able to work here and there. Ill let you know how I get on.

              Comment


                #8
                Originally posted by Neira View Post

                I might be able to put together a quick/small fps project with a weapon that can switch between linetrace fire and projectile, and up it to github. I will just use the fps project in 4.21 with no starter content. I can comment all the Blueprints in the weapon class and Ammo pickup so you can follow along with what I did. School is back in for me in 2 days, So I will be quite busy for a bit, but ill be able to work here and there. Ill let you know how I get on.
                I would appreciate that so much!! Thank you.

                Comment


                  #9
                  Originally posted by inaudiblefuzz View Post

                  I would appreciate that so much!! Thank you.
                  Heya,

                  I've been super-busy with school this week. However its the weekend now. I had a few hours today, finished a small fps weapon project/tutorial and uploaded it to github. No starter content (although I would have been able to make it more flashy). I tried to keep the amount of BP's to a minimum and make everything easy to follow (all the commenting). I have added UI elements, BP interfaces, 1 or 2 macros, just to help with showing whats going on. Dont focus on those areas tho, just look at how the Ammo pickups work, how the Weapon works, and the BPs in the player character. Hopefully it will all make sense as you pull it apart/expand on it. Anyway, I hope it helps. If you have any questions, LMK and ill try to help out when I can. Cheers.

                  Github link:
                  https://github.com/MekeFace/WeaponTutorial

                  Almost forgot, its made in UE4 4.21.2

                  Comment


                    #10
                    Originally posted by Neira View Post

                    Heya,

                    I've been super-busy with school this week. However its the weekend now. I had a few hours today, finished a small fps weapon project/tutorial and uploaded it to github. No starter content (although I would have been able to make it more flashy). I tried to keep the amount of BP's to a minimum and make everything easy to follow (all the commenting). I have added UI elements, BP interfaces, 1 or 2 macros, just to help with showing whats going on. Dont focus on those areas tho, just look at how the Ammo pickups work, how the Weapon works, and the BPs in the player character. Hopefully it will all make sense as you pull it apart/expand on it. Anyway, I hope it helps. If you have any questions, LMK and ill try to help out when I can. Cheers.

                    Github link:
                    https://github.com/MekeFace/WeaponTutorial

                    Almost forgot, its made in UE4 4.21.2
                    That's so nice of you! Thanks

                    Comment


                      #11
                      Originally posted by inaudiblefuzz View Post

                      That's so nice of you! Thanks
                      I had finally figured out the weapon side of things I needed to create a Gun type variable. Then I got stuck on the ammo pickups because I was storing my Ammo within the Gun_Parent. I'm excited to check this out!!

                      Edit**

                      That is beyond awesome!! That's above and beyond what anyone has ever done to help! Thank you.

                      I put the projectile and line trace on the same BP if the linetrace is false then it goes to the projectile. I created a projectile variable which allows me to switch my projectile within the children!! So far everything was great until it came time to work on ammo. I currently have Ammo in the Parent_BP. I noticed that you have yours in the Player. This seems to be a pretty common theme. Am I toast, will I have to re-do my ammo or can I keep it in the Parent? I'm trying to figure out how to create variable ammo types and call them (that's been the project for the last few days).
                      Last edited by inaudiblefuzz; 02-02-2019, 03:03 PM.

                      Comment


                        #12
                        Hiya, Im glad it helped. You can put your variables wherever you like, the only thing you need to decide is how you want your game to work. For example, if I put my Ammo and/or Inventory in my Player Character class, when the player dies they lose everything unless I create a drop inventory on death function. If I put all the vars in the Player Controller, the player keeps everything including leveling etc unless I force them to lose it (Hardcore Mode maybe). If I put the Ammo variable in the weapon and if I drop that weapon, I cant access that Ammo as its stored in the actor I dropped. But yea, you can pretty much put your variables wherever you like, just be mindful it could alter the way your game plays.

                        Once you feel comfortable with your weapon(s) and ammo side of things, you might look into using structs to store your Ammo, Gun(s), or health packs etc etc etc.
                        However, keep everything as simple as you can, so that you can complete your plan and project because that is the most important thing. Being able to create and finish something, and focus on the fun side of it really is what it should be all about.

                        I tend to, from time to time, create something far to ambitious for one person to complete within an acceptable timeframe, and because of that I have a couple of multiplayer projects sitting in my library, I chip away at them, but the end is no where near yet. In the mean time I create small projects and test things out and have fun.

                        All the best with your project!

                        Comment


                          #13
                          Originally posted by Neira View Post
                          Hiya, Im glad it helped. You can put your variables wherever you like, the only thing you need to decide is how you want your game to work. For example, if I put my Ammo and/or Inventory in my Player Character class, when the player dies they lose everything unless I create a drop inventory on death function. If I put all the vars in the Player Controller, the player keeps everything including leveling etc unless I force them to lose it (Hardcore Mode maybe). If I put the Ammo variable in the weapon and if I drop that weapon, I cant access that Ammo as its stored in the actor I dropped. But yea, you can pretty much put your variables wherever you like, just be mindful it could alter the way your game plays.

                          Once you feel comfortable with your weapon(s) and ammo side of things, you might look into using structs to store your Ammo, Gun(s), or health packs etc etc etc.
                          However, keep everything as simple as you can, so that you can complete your plan and project because that is the most important thing. Being able to create and finish something, and focus on the fun side of it really is what it should be all about.

                          I tend to, from time to time, create something far to ambitious for one person to complete within an acceptable timeframe, and because of that I have a couple of multiplayer projects sitting in my library, I chip away at them, but the end is no where near yet. In the mean time I create small projects and test things out and have fun.

                          All the best with your project!
                          I'm a bit stuck with getting my ammo from the Gun_Parent to the Ammo_Blue Print. This is what I have so far. I can't connect the Target to the player character. I believe it's because I should be casting to the Gun_Parent since that's what's holding my ammo variables. I just can't get it to work. Also, this approach (if I did get it to work) would only offer one type of ammo? I have to figure out how to implement a weaponType variable into my Gun_Parent so that I can call it within the various Children? I don't know

                          I'm still going through your project. I really cannot thank you enough for doing that.

                          My game's setup like Quake! No reloads. Just pew, pew until you're out of ammo. So I have a simple ammoCurrent and ammoMax.

                          Comment


                            #14
                            Hiya, correct me if Im wrong, from your picture, when your character runs over your AmmoPickup, you cast to the PlayerCharacter (which is fine) you drag out from the character the reference of the equipped gun, and try to manually add ammo to that gun?

                            Try setting up a Blueprint Interface to do all your communication from Ammo to Weapon. Call it BPI_Weapon (For your guns). Add it to your Weapon Parent Class under Class Settings. Look at the BP_Weapon_Gun_Parent in the Tutorial. Click on Class Settings you'll see I have added BPI_Weapon there.

                            In your Blueprint Interface make an event called AddPrimaryAmmo and AddSecondaryAmmo. Add a reference of the Ammo class and Interger for Amount to the inputs of both events.

                            In your Ammo Pickup class when the player runs over it, you can cast to the player character, draw out a reference of the equipped weapon and then call either AddPrimaryAmmo or AddSecondaryAmmo (message). You always want to make sure you call a message event through the BPI to the weapon. This way you can add different types of ammo to the same gun. Youll have to setup MaxPrimaryAmmo, CurrentPrimaryAmmo, MaxSecondaryAmmo, and CurrentSecondaryAmmo.

                            One thing to note:
                            I placed the main AmmoPool in the Player Character so that you could run over the ammo without a weapon equipped and add it without any hassel.

                            In your AmmoPickup class you might want to do a IsValid check on the equipped weapon. So that you dont throw any errors, due to the AmmoPickup class trying to send ammo to a non existent Weapon. Off the IsValid check - If the weapon is invalid do nothing, If it is valid then add the ammo.

                            Beyond this if you wanted to add incendiary ammo and explosive ammo etc etc, you might want to setup an AmmoPool map variable in your weapon for PrimaryAmmo, and also one for SecondaryAmmo. This way you can store multiple types of primary and secondary ammo in your weapon. Later as your game becomes more complex as you add to it. it might be best to just use a struct for your ammo classes and you can specify in your ammo what gun it can be used in, so on pickup do nothing if you have the wrong gun equipped.

                            I can, at some stage this week, adjust the weapon tutorial to show this working, just let me know how you get on.
                            Last edited by Neira; 02-02-2019, 10:25 PM.

                            Comment


                              #15
                              Hello Neira!

                              Yeah, that is how it was setup. Which i'm 99% sure is wrong. The Ammo is stored in my Gun_Parent so I would need to set it to that... I'm not sure how. I tried "Cast to Gun_Parent" and it wouldn't let me connect to Get Equipped Gun. So I was unable to move forward with that.

                              I would like to keep all of the Ammo stuff within the Gun_Parent. All of the work I have done over the weeks has everything in there and I fear that switching it to the PlayerCharacter will wreck everything I have done.

                              I'm going to try your suggestions and look over the demo map you created again. This stuff can be bonkers are times I really wish they had some community classes on game dev. They have it for everything else!!

                              Comment

                              Working...
                              X