Check condition while button is held and clear the timer

Hi,

I’ve created fire function, which runs Pull Trigger event when LMB is pressed and Release Trigger when it is released. In Pull Trigger I set Timer by function name with looping to simulate automatic fire. Then in Release Trigger I clear that timer. It was working fine until I added ammo counting. From the start of the Release Trigger I check If ammo count is more than and if True, it can continue.

When I stop firing at 0 ammo and want to fire again - I can’t so that condition is working. But, if my Ammo is at least “1” and I hold fire button and not release it, I can fire infinitely even if the ammo is = 0. It is strange because every tutorial shows to handle automatic fire this way, but with conditions is not working properly. I tried a lot of ways to handle it - set timer by event, doOnce or putting conditions in various places in my BP. None of this works.

Right now I disconnected all the other functions to keep the BP as simple as possible.

Imgur

I’ve managed to make it working by moving condition to Event Tick, but I think its not the best way to check it every frame even when player does not try to shoot.

Hey,
I don’t know how your Weapon Trace function looks like. But from what I see I can tell that you check if there is ammo only when you Pull Trigger (so basically only when the button is pressed). Then Weapon Trace is executed at fire rate time intervals but it never checks if you still have ammo.

You can either add the ammo condition check to the Weapon Trace function or in Set Timer By Function Name put PullTrigger instead of Weapon Trace. If you select the latter option, remember to uncheck “Looping” input parameter.

Both options are working. Thank you, I’ve been struggling with this for whole weekend.

Now I’ve got the same problem with the sound and muzzle flash effect. When I check ammo count before Line Trace and it hits 0, traces stop generating but muzzle flash and sound is still going on when I hold fire button. I tried putting the same condition before each effect but without result. I’ve changed Timer for Pull Trigger event and then sound is not ending after I stop shooting and with every new shot it keeps adding same sounds again, so they layer on top of each.

Imgur
Imgur
Imgur
Imgur

Fire Sound Converted is created to let me change the sound effect in the Viewport of BP.
Looping for Timer is not set to on, like on the screenshot.