I’m trying to make an FPS game in which you can pick up weapons and ammo and then shoot monsters. I have a “BP_Weapon” parent, which holds the fire bullet, and reload gun. When I pick up a weapon I want to be able to press a key to select between diffrent ammo types (let’s say 556FMJAmmo/556TracerAmmo/556APAmmo, and the same for 9mm,). When I press that key I also want to select a certain “BP_Projectile” class. How do I link all these? How do I set a gun to be able to use only certain types of ammo and for each selected type of ammo to select a certain projectile class as well?(I’m not using a line trace to shoot my gun). I know I should create the variable in my character’s blueprint, and perhaps use the enumeration blueprint which I’m not very familliar with. I’m pretty much a beginner in UE4. How would you guys do this?
I think the way I would go about this is first by creating an enum class for each weapon type as a separated header so I can easily include it in different classes and inside the weapon class, I can decide the type of weapon for every weapon class. Next, I think I would make an enum for each ammo type(Assault Rifle, SMG, Sniper, etc) that will include the subclasses of each ammo type(AR->FMJ/TRACER, SMG->blabla/blabla). Inside each weapon class, I’d declare a TMAP take takes an ammo type enum and an int for the amount. You can initialize the amount the play starts with, and make input to switch between them. Not sure if this was of help or is the best way to go about this, but yeah
Thanks for the reply!
Your answer surely helped but you introduced me to a new thing: TMaps. I did a bit of research and as far as I understand, a TMap associates a unique key to a value. I am currently still trying to figure out a way to make things work. I am not entirely sure I used the TMap the way you explained.
Here’s my try so far:
My ammo variables are declared in the character’ blueprint because the character is carrying the ammo so it makes sense. I made an enumeration for 556 ammo which includes it’s type of ammo, and as well for 9mm. Then I made an enumeration for guns that use 556, and another one for 9mm. Then I created the TMap.
Right now I can’t even test it because I cannot use the “T” key inside of a weapon BP. I’ll fix that and will come back with a reply shortly.
I hope what I did is what you meant to say.
Maybe Im wrong, but I would create a master-projectile with the main code and each specific ammo would be a children of it with its uniqe “abilites”.
With the e-num you have, you can then switch between them based on your dependance (e.g. weapon type)
I managed to get to a point where it somewhat works.
I pick up the “BP_Loot”, then in the “BP_MainCharacter” the ammo variables change. When I pick up the gun the ammo sets to option 0, and I can use “switch ammo” and it works, but for some reason I have to press it twice. I then set up a different button for each ammo type to see what’s going on, and here’s what’s happening. If I select say option 2 the ammo doesn’t change. If I select it again it changes and it works. If I select a random option say option 3 then select an option diffrent from option 3 then the ammo changes to the last selected one.
Here’s what I’ve done in my child gun BP so far.
I’m sorry if you can’t clearly see the nodes but I had to squeese them in to take one screenshot, because I cannot post more than one picture…
Maybe because you jump from one Add to another instead of calling the needed one.
E.g. you add FMJ. Before adding FMJ, your code gos through “Add AP”
I changed the Tmap a bit and now I’m using the values that I’ve chosen as you can see (40/50/60/70). It still does the same thing…
Here’s the way I’m switching between the options. I did this to see if I can find the problem.
The “Ammo Type” variable just changes between prejectile classes.
Ok i see you are working with interfaces. To call an interface event, you should use the “message” (it has an letter in the upper right corner)
I am using the same interface for my interaction and for the ammo switch. When I search for “Switch Ammo” there is no (Message). If I drag a node line from the “Weapon” object refrence there is no (Message) either.
As you can see in the second picture, the “On Interacted” has a message. If I drag a node line out of “hit actor” and search for switch ammo the (Message) appears. I did that and replaced it with the one I was using. It didn’t do anything…
I’m pretty sure I’m not using it right…
I’m trying to recreate your BP:
(or would you mind to share the BPs?)
So if the actor gets hit, you want to change the ammo based on the weapon?
Here’s something that might help:
I don’t have a HUD that displays my ammo so I’m using a print string that shows me the current carrying ammo on a tick event.
Basically, in my weapon master I have a variable for current carrying ammo and magazine ammo. What I’m trying to do is to set them whenever I change the ammo.
So right now, if I press “T” the amount of ammo that I set the type of ammo to (in this case 40 ammo) then sets the current carrying ammo from the weapon master, then sets the magazine to 0, then reloads(as you can see the picture of the gun itself, the vector).
The reload just takes the current carrying ammo and fills the magazine if there is enough.
The “Reload function” works.
Just now I realized that my print string isn’t looking too well…
I’m not sure but I think it should show something like 40 40 40 40 … every frame and not 40 0 0 0 40 …
I’m sorry If I’m making this way too hard than it seems, or if I’m not explaining and comunicating my problem very well…
I just placed a 2 seconds delay on the Event Tick and it looks like this:
How do I share my bps with you?
here we go
and sometimes its hard to tell what exactly the problem is due the fact that the projects can very complex
There are multiple blueprints used, the weapon master, the weapon, the player, the ammo.
What should I send you? Or just create multiple blueprints and send them all?
all of the needed bps would be awesome
The projectiles are just spheres with collisions and projectile movement components.
If you can’t figure it out, just ignore what I did. Perhaps my approach wasn’t the best. And going back to the main goal… how would you implement the ammo system that I need?
I’ll give you a sample BP