Help with ammo counter and ammo refill.

Hi!
I’m trying to setup ammo counter for the gun in First Person starter content. I managed to get the count go down by 1 after each shot and the gun to stop shooting when ammo count reaches 0. I created another blueprint which is a magazine, but after I pick it up the actor gets destroyed (as intended) but no ammo is added to my conter, nor can I shoot more. My blueprints look like this:

  1. Ammo counter in BP_Rifle (starter content)
  2. My attempt at adding ammo by picking picking up a magazine (simple cube on the level)

If I attach Print String to Cast to BP_Rifle’s Cast Failed output pin, it does print the message.

I’m new to UE5 and I’m learning from YT tutorials and a book, but can’t seem to find any solution there. I tried looking through the forum but didn’t find it here as well.

Help the young padawan please! :smiley:

Hey there @Ettrin! So the way the first person BP is set up is that the gun becomes a component of the skeletal mesh when picked up, it doesn’t retain it’s own actorship in this debacle. So the class of the actor you cast to will always be the first person BP.

This makes handling the ammo on the weapon (in blueprints at least) significantly more annoying. Taking a cue from how the player interacts with the gun BP while it’s connected however does give us a bit of a hint. You can’t directly cast to it from the collision but you can send out events from an event dispatcher for it to receive ammo just like the player does, or an interface so you can set the amount.

This is a bit more of a hassle this way, I’d personally recommend the player BP holds the ammo variable, the gun has it’s own AmmoInClip variable and whenever you reload it pulls ammo from the player BP. That also frees up the logic from the ammo box to be able to add a specific amount to the player BP.

1 Like