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

    #16
    Originally posted by Neira View Post
    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.
    Could I send you my BP to see what you think? Might change? I know it's 'right' there I just can't seem to find it on my own.

    I'm not going after anything crazy. Just a primary weapon. Five weapons in total all with different ammo. No reloads. I have the hud. It's just the darn ammo that keeps kicking me in the pants.

    Comment


      #17
      Hey Inaudiblefuzz,

      Just keep going the way you are. At some stage you could transfer the stuff you need out of your gun into a actor component class and add it to you player controller or character. That way you can keep things working until you are ready to start clearing away the logic you've moved into the component class.

      If you have put your AmmoPool, in your parent weapon class. That means its in all of the children classes.

      *You might need to make it editable on instances of the parent class maybe even expose it on spawn so you can see it in all of your child weapons.

      Do, all your logic in the parent class so it transfers to all of your child weapons. You'll be able to call any event you setup in the parent on any of the children unless you specified otherwise.

      Q) When you run over your weapon pickup, you set the equipped weapon var in your character?
      After you set the equipped weapon properly you can cast to the player character from your ammo pickup and just draw out the equipped weapon var and call the Blueprint Interface event (I hope you setup at some stage) add ammo (message). Or try to add it manually the way you have.

      There is no need to cast to BP_Gun_Parent if your equipped weapon is set properly. It holds the reference of the gun actor equipped.

      The only time you need to cast to your Gun_Parent class is if you are in a situation where a BP doesn't have access to the equipped weapon, or if you are checking for something specific.

      I hope that helps. But yeah keep goin the way you are. Ill try and adjust the Tutorial at some stage to help support where you are heading. Unless you get there first of course! Ill check in when able.

      Keep goin! You'll find the solution to suit! There are many ways to get things to do what you want, each with their own pros and cons, the main thing is to just get things working. Later on you can come back and refine your ideas.


      Oh I just read your last post. Sure, would you upload it to github?? I could make comments on it or slight adjustments to help you make it work. Im sure you'll be like: "ffs yup, I knew that!" Anyway lmk what you want to do.
      Last edited by Neira; 02-03-2019, 03:12 AM.

      Comment


        #18
        Originally posted by Neira View Post
        Hey Inaudiblefuzz,

        Just keep going the way you are. At some stage you could transfer the stuff you need out of your gun into a actor component class and add it to you player controller or character. That way you can keep things working until you are ready to start clearing away the logic you've moved into the component class.

        If you have put your AmmoPool, in your parent weapon class. That means its in all of the children classes.

        *You might need to make it editable on instances of the parent class maybe even expose it on spawn so you can see it in all of your child weapons.

        Do, all your logic in the parent class so it transfers to all of your child weapons. You'll be able to call any event you setup in the parent on any of the children unless you specified otherwise.

        Q) When you run over your weapon pickup, you set the equipped weapon var in your character?
        After you set the equipped weapon properly you can cast to the player character from your ammo pickup and just draw out the equipped weapon var and call the Blueprint Interface event (I hope you setup at some stage) add ammo (message). Or try to add it manually the way you have.

        There is no need to cast to BP_Gun_Parent if your equipped weapon is set properly. It holds the reference of the gun actor equipped.

        The only time you need to cast to your Gun_Parent class is if you are in a situation where a BP doesn't have access to the equipped weapon, or if you are checking for something specific.

        I hope that helps. But yeah keep goin the way you are. Ill try and adjust the Tutorial at some stage to help support where you are heading. Unless you get there first of course! Ill check in when able.

        Keep goin! You'll find the solution to suit! There are many ways to get things to do what you want, each with their own pros and cons, the main thing is to just get things working. Later on you can come back and refine your ideas.


        Oh I just read your last post. Sure, would you upload it to github?? I could make comments on it or slight adjustments to help you make it work. Im sure you'll be like: "ffs yup, I knew that!" Anyway lmk what you want to do.
        I'm just so worried it's something so trivial that's right there in my face that I keep missing! I'll send you a link for Github in a PM to see what you think. Any notes / tips would help very much!

        Comment


          #19
          It's uploading to Github now. Hopefully I did it right. I just always assumed... It was a nice / simple drag and drop Cloud setup... Man - Was I wrong :P

          Comment


            #20
            yea ikr, lmk the link when done & ill see how I can help.

            Comment


              #21
              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
              hey is there a possible way I could get this download link please as well ?

              Comment

              Working...
              X