Announcement

Collapse
No announcement yet.

Elegant solution to play certain animations depending on what weapon a player is using?

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

    Elegant solution to play certain animations depending on what weapon a player is using?

    I currently have my animations setup for my primary and secondary weapons just fine- a blend by bool check in the animation blueprint decides if the current weapon is primary, and if it is, it plays the primary animations, if not, it plays the secondary animations. However, I have many more weapons ready to implement, and it would be possible for the player to pick up more than 2 at a time. I did get a clumsy setup working for 3 weapons- a messy string of bool checks which goes through each weapon and checks if they are currently equipped. The problem here is that eventually the amount of checks for each action (aim/reload etc.) will become huge and very hard to manage. I have looked around extensively but the only examples I could find were of the ShooterGame- but that only has 2 weapons, therefore it decides on what animations to play with a bool check. What would be the "best" way to efficiently check what weapon is equipped, and play the corresponding animations, assuming a player could pick up 12 different weapons at any time in a game? I was thinking mabye a select on an enum of weapon names, but my initial tests failed to play any anims there, so thought I'd ask here and see if anyone could shed light on it. Many games (including Unreal Tournament) have many different weapons and animations that play fine, so I know there must be a standard way of going about this! Thanks!
    ARTSTATION: https://www.artstation.com/artist/noisestorm

    #2
    I've been thinking about this lately as well. with my limited knowledge of the UE4 anim system, the best solution I could come up with would be to make a BlendSpace with as many divisions as number of weapons you have, and make one of these BlendSpaces per animation "action".
    so imagine you have 3 animations per weapon and 6 weapons, you make 3 BlendSpaces each of which will have 6 animations to choose from. when the animation is triggered it will play Fire1, Fire2 or Fire3 accordingly, and each of the 3 fires will use the apropriate animation for the corresponding weapon.

    but perhaps there's a better way, I'm all ears
    Follow me on Twitter!
    Developer of Elium - Prison Escape
    Localized IBL for UE4

    Comment


      #3
      On character bp create an integer variable. For every weapon you equip, set this integer variable to a fifferent value. This value will be switching between state machines on anim bp.

      On anim bp make all your state machines for different weapons. Get a node switch by int( cant remember exact name). Hook your state machines to that node and hook the node to final state.

      On anim bp event graph cast to character and get the integer variable that you created earlyer. Now create a new integer variable in anim bp.

      Now use the variable you got from character bp to set the integer on anmib bp.

      Go to anim graph. Get the integer variable. Hook it up to the switch by int node where your state machines are connected. Done.

      Wow I am bad at explaining stuff ))

      Comment


        #4
        It's pretty easy actualy all you have to do is expose the animation sequence-blendspace-aimoffset you want to be custom and give it a variable of the same type than you can change the variable based on what weapon you have equiped

        Comment


          #5
          Originally posted by Pabooklas View Post
          On character bp create an integer variable. For every weapon you equip, set this integer variable to a fifferent value. This value will be switching between state machines on anim bp.

          On anim bp make all your state machines for different weapons. Get a node switch by int( cant remember exact name). Hook your state machines to that node and hook the node to final state.

          On anim bp event graph cast to character and get the integer variable that you created earlyer. Now create a new integer variable in anim bp.

          Now use the variable you got from character bp to set the integer on anmib bp.

          Go to anim graph. Get the integer variable. Hook it up to the switch by int node where your state machines are connected. Done.

          Wow I am bad at explaining stuff ))
          Thanks for this! I had a similar setup before except I tried a switch on enum- which didn't seem to work out. I'll work on it again using the switch on int and see- I probably made some unrelated error last time! Good to know this method is doable
          ARTSTATION: https://www.artstation.com/artist/noisestorm

          Comment


            #6
            create weapons enum. Put all your weapons in the enum. You can switch the weapons in enum like this: Click image for larger version

Name:	ChangeWeapon.png
Views:	1
Size:	145.2 KB
ID:	1074918

            This is in characterBP.

            next go to anim bp and get this enum by casting to character bp and getting this enum. Create a variable in anim bp. Call it weapons or whatever. Set its type to the weapons enum you created earlier. Drag it out and select set. Setit with enum variable from character bp. It looks like this: Click image for larger version

Name:	EventGraphAnim.png
Views:	1
Size:	139.8 KB
ID:	1074919

            Go to anim graph. Get your enum weapons variable. Drag out a pin and type blend poses enum weapons. Get that node. Right click on it and add pins with all the names of your weapons. Connect state machines. Connect the blend poses by enum with final pose. It will look something like this: Click image for larger version

Name:	AnimGraph.png
Views:	1
Size:	134.6 KB
ID:	1074920

            Good luck!

            Comment


              #7
              Originally posted by Pabooklas View Post
              create weapons enum. Put all your weapons in the enum. You can switch the weapons in enum like this: [ATTACH=CONFIG]36069[/ATTACH]

              This is in characterBP.

              next go to anim bp and get this enum by casting to character bp and getting this enum. Create a variable in anim bp. Call it weapons or whatever. Set its type to the weapons enum you created earlier. Drag it out and select set. Setit with enum variable from character bp. It looks like this: [ATTACH=CONFIG]36070[/ATTACH]

              Go to anim graph. Get your enum weapons variable. Drag out a pin and type blend poses enum weapons. Get that node. Right click on it and add pins with all the names of your weapons. Connect state machines. Connect the blend poses by enum with final pose. It will look something like this: [ATTACH=CONFIG]36071[/ATTACH]

              Good luck!
              Wow thank you, this is exactly what I was looking for!

              P.S. sorry for the late reply, haven't checked on this thread in a while, but the info is greatly appreciated
              ARTSTATION: https://www.artstation.com/artist/noisestorm

              Comment


                #8
                My pleasure!

                Comment


                  #9
                  Quite helpful.
                  I have been searching the forums and google, with very little results. Was going to post a question myself until I saw this answer!
                  WIP Thread _ Modular Packs
                  ___________________________________
                  http://www.permafrostdevelopment.com/

                  http://www.indiedb.com/games/the-absence
                  https://twitter.com/PermafrostDevs

                  Comment


                    #10
                    What I have done took like 4 months to make it work well, but it works.

                    Basically, I have a special object called "ItemAnimList". This simply holds a list of animations for a certain weapon and skeleton. An example would be "pistolPlayer", for pistols the player would use.
                    Now the item can simply run a function called "setAnim('aim'), and it finds the correct animation, and sets that as it's current animation.

                    The anim blueprint then detects the change in animation, and switches it. Boom!
                    -Josh Steinhauer ~ HERO ~ My Blog ~ My Twitter

                    Comment


                      #11
                      Good thread, I was also about to go through the same process and was wondering whether multiple state machines, one for each type of weapon blended in the animGraph via int was a legit solution, apparently it is.
                      Cheers everybody!

                      Comment


                        #12
                        Originally posted by Adeptus View Post
                        Good thread, I was also about to go through the same process and was wondering whether multiple state machines, one for each type of weapon blended in the animGraph via int was a legit solution, apparently it is.
                        Cheers everybody!
                        The int method I was writing from my (bad) memory so it might be of. But the enum method with pics is 100% good. Glad this old thread is still useful to people.

                        Comment


                          #13
                          Thanks Pabooklas.

                          That right click to add more poses is not very obvious, thanks for pointing it out

                          Nick

                          Comment


                            #14
                            In our project we have our load out selection set up like Shooter and it "does" work well as an example and can support more than 2 weapons.

                            example.

                            Load the Player Pawn BP and under the Inventory branch in details you add additional weapon BP's to the load out. So if you add 5 more weapons each can be selected as you rotate the mouse wheel.

                            In the weapons BP all the information as to unique weapon requirements is contained with in the BP and you can just cast for the info you need from the current player pawn.

                            Everything is contained in the weapon BP like 1st and 3rd person as well as weapon animations and weapon specs and you only have to cast for it once based on the current weapon selection. Slick way to do it because once set up in the player animations you can add as many weapons as you wish with out having to add unique requirements to the player character animation BP.

                            P.S. A requirement ideally suitable for a plugin solution.
                            Clarke's third law: Any sufficiently advanced technology is indistinguishable from magic.
                            Custom Map Maker Discord
                            https://discord.gg/t48GHkA
                            Urban Terror https://www.urbanterror.info/home/

                            Comment


                              #15
                              Originally posted by Nick Jackson View Post
                              Thanks Pabooklas.

                              That right click to add more poses is not very obvious, thanks for pointing it out

                              Nick
                              No problem man.

                              Comment

                              Working...
                              X