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.
Cast to the parent class. If you’ve implemented ammo routines in the parent class, then you can call an ammo function from there
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.
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)
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.
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!
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.
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.
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 . But it is really something I can’t seem to wrap my head around just yet. I do appreciate you helping though!
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
which is ok, it works, but it’s not using the interface ( notice there’s no envelope ).
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:
Setup for the shotgun and freezer ammo pickup BP’s:
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.