Download

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!

1 Like

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

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 :)))

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

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 :slight_smile:

create weapons enum. Put all your weapons in the enum. You can switch the weapons in enum like this:

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:

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:

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 :slight_smile:

My pleasure!

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!

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! :smiley:

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. :slight_smile: But the enum method with pics is 100% good. Glad this old thread is still useful to people.

Thanks Pabooklas.

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

Nick

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. :wink:

No problem man.

Hi, I’ve followed this exactly yet I can’t quite get the switch weapons to work. I’ve added different animations for each pose and I replicated everything in your pictures yet my character won’t “switch weapons” in game; he just stays in the same pose the entire time. Any help would be greatly appreciated, thank you.

2 years later and this post is still helpful to a Newb Like myself. Thanks Guys I am so surprised noone has done a tutorial on this topic as of yet!!

My hip fire aimoffset works but for some reason everytime i switch to the starter pack ironsights aim offset i made he looks like he is frozen in the idle position of the hip fire, when i go into the aim offset for the ironsight it looks like it works perfectly but something with it running in the animbp is messing it up.

What A Pain In The ■■■, Just Let Us Use Different BP Animation Files Depending On The Gun, Duh