How do I stop this from triggering twice????

How do I make sure the EndLevel does not load twice?
I thought by setting up a bool would work, but apparently I’m missing something.
The action is bound to the mouse left click and if clicking very fast, no matter what I do, every now and then EndLevel gets loaded twice.

See screenshots below…

When this happens it messes up my math in the UMG and the grand total for points is doubled.

I tried disabling player input inside the EndLevel event but that still doesn’t seem to work.
I’m open to any ideas/suggestions.

Without knowing the purpose of the delays, try putting a “Do Once” at the beginning and reset it on “True” of the branches.

beginning, meaning right after LeftMouseButton? or after the first branch?
the delays are just my failed attempts at trying to make this work. No other purpose

Right after the clickmouse event.

Okay when he does not have ammo and you click will go to the false branch

The solution is when you press the left mouse (I suggest making it an action map and assigning a mouse click)
Make a branch for the variable(Game Over) will prevent it from working twice

This thing is making me go crazy… let me show you what I have so far and why it breaks something else now.
Give me 5min to screenshot everything

so setting and resetting the gameover variable, works for the first part. if user still has bullets → game is not over as soon as the game is over and reaches EndLevel → set the bool to true → this will prevent the mouse click from firing again.
However, once EndLevel widget is loaded… whether the player finished or not, when I load the next level or restart the level, the do once gate seems to be closed and the player can no longer shoot. I tried setting the variable to false again, but it did not work.
To complicate matters even more, in PC on EventBeginPlay I have a DisableInput, which gets re-enabled when the HUD loads. (This part was working fine before) Not sure if this is what’s causing the input lock or the DoOnce not resetting the gate.

See images below…

When the game starts, in PC I disable input:

Mouse click for shooting:

In the HUD UI, I re-enable input. (this worked fine before I added the DoOnce node)

Now on subsequent levels, or if I redirect the user to the MainMenu and start playing the 1st level again, the input is locked :frowning:
(during the same game session)

I don’t recommend using do once here, it’s not a looping event
instead, using branch seems more logical try it and let me know what you got

@Admiral-0
but I had a branch to begin with…

see first post.

Should I add another branch before that?

you could use and bool
or just add another branch instead of do once

Ok, I have to admit… I’m more confused… :slight_smile:

Is seems to be working… but why?
I’m trying to understand the logic… Why, by adding another branch before the one that is checking for bullets works??
Will need to test it more and make sure EndLevel doesn’t load twice again, but as of right now it seems to be ok.

@Admiral-0
if you don’t mind, can you please dumb it down for me. Why is this new branch not redundant??? Isn’t doing the same thing as the next one???

It’s straightforward logic, every time you press the key you are checking if the game is over or not
then you determine which path code should take
by default, the Gameover variable has a false value then you change it with some conditions

I suggest you learn more about basic programming, especially the theoretical part there is a lot of essential things to know, and this will help you to make a better code structure
and more logical

hope this helpful

@Admiral-0

thanks for helping. I really appreciate it.
I get it now. The reason I kind of got confused was because I had 2 check twice whether the user had bullets left or not. (Just in case the bullet fired was the last the player had). So every time I would end up on the False branch twice when that was the case.
I get it now, by setting the gameover var and adding a branch before all that it stops the flow and only 1 branch of the hasAmmo will ever execute, even on the last bullet.

1 Like