Hello, I’ve been working on a shooter and was wondering if there was a way to add different reload animations depending on how much ammo is in the gun. I’m working on a double-barrel shotgun with two hammers and wanted to have each hammer move individually for each shot. For example, the player clicks mouse 1 once and the left hammer goes down. Player clicks mouse 1 a second time and the right hammer goes down.
When the gun is fully loaded
After 1st shot
After 2nd Shot
Hi @Gangster_Granny ,
if you use anim BP, you can use Blend Poses by int. With Blend poses by int, you can change animation based on int value, you can use your ammo variable for the int value. Example below:
Pls tell me if its not the case
Thank you, @ImAGoodSpoon1
I accidentally miss-typed what I was trying to ask. I was trying to see if there was a way to add different firing animations for each time I shot, not reload.
I do appreciate your help still since it will come in handy for reloading the gun when it still has ammo.
You can also use the ammo example for different firing animation. Example, IF your ammo still 2, then you will play Firing animation A, if ammo 1, play firing animation B, etc. I think you still can do it with Blend poses by int. If you use Enum, you can also use blend poses by your enum instead of integer.
Example of Blend poses by enum.
1 Like
I’m using integers for my ammo. How would I let the game know to play a different animation based on the number? I would like to do it the way you mentioned “IF your ammo still 2, then you will play Firing animation A, if ammo 1, play firing animation B” but I’m not sure how to go about it.
This is from the gun’s Anim BP
How would I get it to know when to change pose?
Hi @Gangster_Granny ,
First, let me tell you how can you increase blend pin if you haven’t know yet (since I forgot to told you before). You can just right click at the node, then click
Add Blend Pin like what I show you in the image above.
Here’s how Blend poses work:
IF my Ammo Count variable value is 2, THEN the animation that is played, is the animation from Blend Pose 2.
IF my Ammo Count Variable value is 1, THEN the animation from Blend Pose 1 will be played.
IF my Ammo Count variable value is 0, THEN animation from Blend Pose 0 will be played.
The Anim BP will automatically switch the animation that will be played, based on the value of “Active Child Index Pin” so you have to also make sure that when you shot (or there is ammo value change), you also need to make sure that the value in the Anim BP also already updated (IF you’re using pointer maybe you don’t need to do anything if its already calculated inside that object pointer).
And I will translate your image above:
- IF Amount Loaded value is 0, THEN Sawed_Off_Shotgun_Anim_Root_Shoot01 animation will be played
- IF Amount Loaded value is 1, THEN Sawed_Off_Shotgun_Anim_Root_Shoot02 animation will be played
I don’t understand how you handle the amount loaded, but you have to make sure to match the blend pose number (Blend Pose 1, Blend Pose 2, etc) with the value that you want. For example, IF you want to play Sawed_Off_Shotgun_Anim_Root_Shoot01 anim if Amount Loaded variable value is 1, then you fit that anim into Blend Pose 1.
If my comment is not the case, then you can just tell me
I fixed it but it still isn’t playing the animation based on the value of the integer. I do appreciate you trying to help me figure this out but yeah I don’t think this way of doing it will work out in my case.
I see, could you describe what happen with that blend pose? I mean, why is not working. Is it not playing the right animation? or it doesnt even switch to any anim? maybe I could help you if you want
It’s just not playing any animation in general except for blend pose 0. I’m guessing it might have something to do with how I’m calling the integer.
Every time I shoot in game none of the animations play and I get this error
Blueprint Runtime Error: “Accessed None trying to read property Sawed0ff”. Node: Blend Poses by int Graph: Sawed_Off_Shotgun_Shooting Function: Execute Ubergraph Anim BP Sawed Off Blueprint: AnimBP_Sawed_Off
I wish I could send multiple screenshots but I can’t because new users can only put one embedded media item in a post.
This might help. I did watch this guy’s video on how to set up my ammo. I created the functions however in my gun’s BP, not my player character’s.
Hello,
I think the problem is within your error itself. “Accessed None trying to read property Sawed0ff”. means that your Sawed Off doesn’t even valid. Do you already fill that “SawedOff” variable in the Anim BP? if you have, could you show me how you fill that variable?
The “SawedOff” variable is just an Object Type variable that references the shotgun’s BP so that way I can get the “Amount Loaded” variable from the shotgun’s BP.
All I have set up for the variable is this
yes I know. What I mean is, do you already fill / initialize the SawedOff variable before?
Here is the example of what I mean.
@ImAGoodSpoon1
No, I haven’t done anything like that. Would I just do what you showed but change the Cast to my sawed-off BP instead?
@Gangster_Granny ,
Yes you should do that. You should initialize the Sawed Off to the right thing, If you don’t do this, the pointer will be invalid because its nullptr. You right, you should change the cast to your BP_Sawed Off.
Okay, it works now that I actually set up the variable, however, it only plays the animations once. Do you know any way to fix this so the animations can be played again after I reload?
I think it should be played automatically if the implementation is correct. Do you already update your Amount Loaded correctly after reload?
@ImAGoodSpoon1
I’m honestly not sure anymore considering I didn’t set up the other variable correctly. I feel like the Amount Loaded is fine since after I reload I can shoot two rounds again.
Maybe you can see something that I did wrong in my BP’s
How the player reloads
The Reload and Use Ammo functions.
Hey, I don’t think there is a problem but because of I don’t know how your gun work, I also don’t think my evaluation is correct.
What you can do to easily look where is the problem is just put a print text node to check your amount loaded value
Just put that after you change your amount loaded, and make sure that everything is doing correctly and align with the anim BP.
@ImAGoodSpoon1
I’ve been playing around with it for a while and realized it has something to do with my reload animation. If I get rid of the reload animation in my character BP then the gun works fine, it just doesn’t have a reload animation now.
Do you know of any other ways I could have the reload animation play?
Hey @Gangster_Granny,
How do you play the reload animation? and why you put it in character BP not in the same gun anim BP where you play the gun anim?