Help Setting Up AnimBP to Check if Holding Weapon

Hello,

I’m having some trouble configuring my CharacterAnimBP to include different animations when holding various weapons. I’m currently only working with one weapon and if I can get it working I’ll know how to setup for the rest later. So far I have:

  1. Created a blend space “Jog_Holding_AR” for the animations related to this weapon.
  2. Added a new state “HoldingAR” in my state machine.
  3. Mapped the blend space to the new state
  4. Created a bool inside my weapon bp “SK_GunTEST” that sets it to true once the weapon has been picked up.
  5. Attempted to cast to this bp from inside the anim bp “CharacterAnimBP”.

I’m sure I’m overcomplicating this but all I’m trying to do is be able to access this boolean from the anim bp so that I can check if it’s true or false and update the animation accordingly. From what I found online it seems the only way to do this is by using a “cast to” node, but the problem is I don’t know how to set up the object portion. If there is a better method or solution to my current setup please let me know, any help would be appreciated!

  1. Don’t use different states for holding different weapons.
  2. Use an Enum to define which (if at all) weapon a character is holding. Make a Interface for the communication between the AnimBP and the pawn. This will make it easier if you have different pawns.
  3. With that enum simply use a Blend by enum animation node to pick the correct animation for the weapon.
  4. Use a Layer blend by bone node to split your animation system to the upper and lower body. That way you don’t need a separate blendspace for every weapon AND every movement type:

You will also need two state machines, one for the upper and one for the lower body.

Thank you for your solution! However, I think this may be too complex for my game. My apologies, I didn’t give any context there. The game is going to have a blocky art style so fine details in animations aren’t going to matter too much. Also, only one pawn as it’s single player and there will only be 3-5 blend spaces I’ll need for each weapon ‘category’ (ARs, Pistols, Shotguns, Rocket Launchers).

If you split your animation system in upper and lower body you don’t need 3-5 blend spaces for each gun.
You will only need 1-2 (idle / moving).
Then you can also use animation from different sources for your lower and upper body. For example use the Paragon animations for your lower body.

Hmm I still think that’s overkill for what I’m trying to achieve but maybe it’ll come in handy later down the road! The game is going to be very simplistic and use a minimal amount of animations. I was taking about 3-5 blend spaces total—not for each weapon, that would be insane! haha

Would you mind posting a screenshot of the event graph or do you have a tutorial that you used for this that you could link to?

My event graph woun’t be very helpfull for you, because I do my calculations not in the animbp but in a seperate component.
Or do you mean the state machines?

Sure, seeing inside the state machines might help. Honestly though there is a lot going on in your’s that I’m not familiar with, it would be easier if I just had a method to access the isHoldingAR boolean I created from within my anim bp.

State machine lower body:

Idle state (upper body):

Moving state (lower body):

Note that I currently don’t have any “to move” or “to stop” (= start / stop moving) animations implementet and therefore not states for them.

Getting a variable from the pawn is just casting the owner (Try Get Pawn Owner()) to your class and then getting the variable.
Or use an interface.

Thanks for your continued help! So the only thing is that I’m not getting the variable from my pawn, but instead my weapon blueprint. This is what’s making it hard as I can’t figure out what to attach to the object of my ‘cast to’. Anything that has a reference to ‘self’ won’t work because it’s not inherited from the pawn class.

???
Adding a variable to a weapon to check if it’s picked up doesn’t make much sense.
There is a function GetOwner() which should be set once that weapon is picked up and set to null, once droped.
If you want’t to know if the actor has any weapon equipped, you can make a function, that checks if the pawn’s variable EquippedWeapon (or similar name) is null or not. Because when you pick up a weapon, you need to store a pointer to it in your pawn.

Ok I figured this out over the weekend and it was so simple! Sorry, I’m learning as I go so I was going about this backwards. Initially, I was trying to store the boolean locally inside my weapon bp, then trying to cast to it from my character bp to try and reference it somehow. Once I realized the solution I laughed at how simple it was. I got it working by creating the bool inside the character bp, then casting to it from the weapon bp and setting it to true once picked up. Adding images for anyone who might come across this with the same question.