During one of our Coding and Scripting for Games workshops (CSGO), I decided to mess around and try to create an ammo system for the standard first player mode in Unreal Engine 5.
The unreal engine first person mode comes with a first person character with a rifle which can shoot. This gun can endlessly shoot round ball like projectiles that bounce off of surfaces.
In the event already created by the first person game mode, I plugged a sequence into the triggered event. This event is for shooting the gun. When left click is triggered, it will spawn an actor (the projectile) and shoot it forwards. As you can see in the blueprint above on the sequence's zero plug, the "Ammo" variable is set at 30. Every trigger of the event will take away one unit from the assigned value of "Ammo" which is currently set at 30.
Then in the second sequence plug, I created a branch. This branch is testing whether our "Ammo" variable is equal to or greater than zero. If the system detects that the "Ammo" variable reaches zero, the Boolean will show as true and then the string "Out of ammo!" will print on the screen.
As you can see there are multiple print strings on the screen. This is because the gun will no longer spawn a projectile and will only print the text with every triggering event.
If the Boolean event is false, then the gun will continue to spawn projectiles, until the ammo count reaches zero and prints the string.
I was initially planning to create a reload function, but was struggling to figure out how to do it. I checked out some videos online, but all of their gun blueprints were very different to my own. I will continue to look into this in the future, as it is an important thing to know, especially as I plan on making shooter games in the future.
I plan on adding the reload function and an ammo counter in the future. I have already made a widget for the ammo counter, but I'm yet to figure out how to make the numbers, reflect the accurate bullet/projectile count.
Did you like this post? Tell us