Link Ammo Pickup From Separate Weapon BP Class to First Person Character

Hello! So because I have all 7 of my weapons in separate child BP classes, the ammo decrements are within the individual classes which makes sense and works. However, for the ammo pickups that the player would collide with and add ammo to the weapon, I have to cast it to the weapon BP class since that’s where the ammo decrements are. This makes it so now the first person character can not collide and pick up the ammo
(Images Below).

So my question is how would I make it so that the first person character is able to still pick up the ammo while the overlap is being casted to the weapon BP class to add more ammo correctly? I feel like I’m just missing one little thing, but I have no idea what it is. I could also be missing a lot, lol.


Thanks for your help!

Two ways to do it

  1. Cast to the parent class. If you’ve implemented ammo routines in the parent class, then you can call an ammo function from there

  2. If you don’t have a clear pattern, and the way the ammo works is different in every class, then use blueprint interfaces. That way, you don’t even have to cast. Just say ‘add ammo’ to the actor.

2 Likes

Blueprint Interfaces sound like a good option since yeah, all of the weapons have different ammo types and variables in each of the child actors. However, I’m very unfamiliar with how to set those up. I understand they are a read only function that can share data between more than one blueprint, but I haven’t ever really messed with them yet.

I have tried to find some tutorials on these, but a lot of the ones I found deal with having interfaces setup with an action mapping (for example, interacting with items or whatever). All I need is just when the player overlaps the sphere collision on the ammo. It seems more basic, but I am a heavy visual learner when it comes to things like blueprints.

To use one weapon out of the seven as an example, how could I go about setting up an ammo pickup interface, if you will, between the first person character, the shotgun BP class, and the shotgun ammo pickup? (I’d assume I need one for those three classes since those are all what I want to be linked)

Thank you for your help!

A better way of thinking about it would be, you can send a message to any kind of actor, without knowing what kind of thing it is.

Your pickup could look like this

I made the blueprint interface to send two types, amount and ammo type.

In the player, it would say

So you can’t use the wrong kind of ammo.

And, to reload the shotgun, you would also send it a message. This way, the shotgun won’t take pistol ammo.

Okay so I have applied this formula you have kindly shared. I did have to make an Enum for ammo types since I didn’t have any (I just did the 2 ammo types for the shotgun for now).

I think I’m still missing something or I could be misunderstanding the info you’ve shared as there is still an issue. The player can now pick up the ammo again, but it does not add 15 ammo to the shotgun. Maybe I need more info for the Enum or maybe I have something in the wrong blueprint class or the wrong variables are being used? I’m not quite sure.



Thanks again!

It looks good :slight_smile:

You don’t have to use ammo types, of course. I was just trying to pre-empt the next question.

I’d put a print string here

Is this event getting called? Print out the ammo type.

Ah okay, gotcha.

After placing the print string in this spot, I found that no string was appearing on screen so it seems that it isn’t going through. Suggestions for that?

Always happy to supply more images and info of Blueprints and such if needed!

Just to double check something. You need this on

image

Sometimes print strings don’t show unless this is set.

Also try a cast here to you player character

image

Otherwise overlap with anything will trigger the capsule.

Yeah, I had the stat box checked :+1:

Even after adding in a cast to the first person character, there was still no string that appeared on screen. I added it in like this, which could not be right, but yeah.

And this is in your player?

And the player implements the interface?

That is in my Weapon Blueprint class that is one of seven child classes of a parent blueprint. This is because the ammo variables were made in there.


The first person character BP has the codes for switching between the weapons and has primary, secondary, and tertiary fire events that call to the weapon blueprint classes.

Ah. Ok.

So the message is going to your player, not the weapon.

You need to implement it in your player, and pass that info to the to weapon.

So the player implements

image

and immediately does

image

to the weapon.

What all would I need to bring into the first person BP? Are you saying I need to basically copy that same formula from the weapon BP and paste it into the first person BP? If that is the case, I’d have to also bring over the variables so that would work right. Otherwise, how would I use that in the first person BP to send the information (that message node) in the ammo pickup BP to the weapon BP?

I’m probably overthinking this by a longshot and I apologize for that, clearly you can tell I have never done this before :rofl:. But it is really something I can’t seem to wrap my head around just yet. I do appreciate you helping though!

When you overlap, the player overlaps, not the weapon.

So you can only send the message to the player.

The player doesn’t need any new variables. Just send the message to the player, and the player then sends it to the weapon.

So the player needs to implement the interface as well as the weapon.

Ammo pickup

Player

image

Weapon

But: the type of the weapon variable in the player, needs to be ‘Actor’. It’s ok to have any type of blueprint or whatever as your weapon in the player, but the variable you call the interface on, needs to be actor.

Otherwise you get

image

which is ok, it works, but it’s not using the interface ( notice there’s no envelope ).

UNLESS unless unless :smiley:

It really depends how you’re doing it.

If you have spawned your weapon in the player’s hand, and the weapon can overlap with the ammo pickup, then it can talk directly to the weapon. No need to go via the player…

I have it set to overlap with the player I believe.

And yes I see now, you just meant implement the interface in the first person BP as well.

I now have everything setup as you have said with the interfaces all implemented and I’ve also added in the second ammo type for the shotgun I have here. So there are now two functions within the interfaces for that.

Setup for the first person BP:
FPC Ammo Message

Setup for the shotgun and freezer ammo pickup BP’s:


Setup for the ammo checks in the shotgun BP:

Everything seemed to make sense and looked right to me. However, the ammo is still not being added to the weapon for some reason. I did some print strings on the player setup and those did work as the “ShotgunAmmo” and “FreezerAmmo” as well as their amounts correctly popped up. But for some strange reason, the ammo increase still does not get relayed to the weapon BP, or rather I still can’t keep shooting after the ammo is depleted and I’ve pickup up more ammo.

The “Shotgun” variable in the player setup is a Child Actor Component. Does that maybe have something to do with this? You did mention that the type of weapon variable needs to be an Actor and would result in the node that isn’t using the interface, which the child actor component is not compatible with.

All correct apart from

image

The whole point is that you are passing the ammo type, so you only need one event :slight_smile:

Just INT_ammo

Yes. Child actor components are a fiddle, if you want to call interfaces on them you have to

image

Pull from the child actor component and look for ‘get child actor’.

Ah I see, yeah the ammo type takes care of that. Knocked it back down to just the one event.

Huh. I don’t seem to get that option of “Get Child Actor”.

The only option I get is to “Get Child Component (Shotgun)”
FPC Ammo Message Child Component
Unless that child index input needs something in it…

Otherwise I just leave it like this:
FPC Ammo Message

Either way, both don’t seem to work. I still can’t shoot again after the player picks up the ammo.

They don’t work, because you’re not getting to the actor.

Is it a child actor, does it look like that?

image