Download

help! firing event so fast it passes a "do once node"

Hi. I have a hardware issue with my mouse that causes double clicks sometimes (not ue4 related).
however, this presented an interesting problem, that when I use my left click event, it sometimes fires twice, allowing my players to do double attacks. This means they can cheat.
Even with a “do once” node, and running a dedicated server, this still happens. the two events fire so fast that the event is called twice before it even hits the “do once” node.

anyone experience this or know how I can prevent it from firing twice?

Hi @CrimsonFeyStu
i am not sure, even if you doubleclick super fast you should be able to do only 1 action with proper nodes.
show us a screenshot of the bllueprint

I think the code is running faster than you can click. Can you show the code?

no, the click is indeed running faster than the code


if i click as fast as I can, i cannot click fast enough however, when my mouse glitches it does indeed fire twice

I should clarfiy the reset is on a 1 second timer so I can only attack once per second

Try substituting the reset event with a delay node connected to reset and place it after the Do Once.

image


it is double firing with a single click

There has to be something else listening to that input. Do you have “consume input” enabled?

consume input is enabled

Change the text of that print. Last thing I can think of to check if it’s executing twice lol (still don’t think it is on same blueprint)

Hmm…

What about catching it yourself?

Everytime the node triggers, have a look at the time, and the last time it triggered. If they’re too close together, reject it

image

1 Like

u resseting the node every 0.2 seconds. thats a really short amount of time that it looks instantaneous

i had it to a full second before tho. for it really isnt firing on a second bp either. its an issue that only occurs when my mouse double click (hardware glitch) and it happens in other apps too not just unreal. Im just trying to figure out how to stop it from double firing.

i will try this one and let you know

The only two ways it can double fire are if second click is after the delay or there are two blueprint printing same text.

Unreal will just ignore the input until the code finishes executing, not create an instance of the code and run it parallel no matter the speed of the input signal.

and yet the event is firing twice. are you 100% sure there is no way? because It is definitely happening. the double fire is extremely fast. like tiny fractions of a second, almost simultaneous. ive tried resetting the do once node on a one second timer and it still double fires sometimes when my mouse bugs

With a single instance of you actor, the only one waiting for the input:
It does this - click → read code → Do Once → execute Print → wait for delay duration → reset do once and wait for new click (you can click a thousand times and nothing past Do Once will be executed until this step).

Not this - click → read code → click → read code again while finishing reading the last → execute Do Once twice → execute Print twice → wait for two delay duration → reset do once twice

You can have events firing faster than frame rate, but not if with a delay duration > frame time. There is no way around this.

It doesn’t matter how fast the hardware event fires, as this just triggers a hardware interrupt, which places and even into the operating system event queue.

Events are then processed by UE4 from this queue each frame using a loop along the lines of:

While there are events in the queue:

  • Pop Next Event off Queue
  • Process Event

It’s the last bit, “Process Event,” which actually calls the blueprint event node; this action waits for that event node to return, i.e. the end of the execute thread (or a delay node, which is actually just setting a timer to fire another event as a separate thread, but displayed as a single thread).

This means that the first event has already finished and locked the Do Once node before the second event is processed.

Note UE4 may be buffering the OS events into its own even queue I haven’t checked the implementation details, also timer events may be included in this loop or use a separate loop however this is irrelevant to the argument.

As for debugging, I suggest, adding an index you increment for each event and one for each tick (i.e. frame), finally, a variable for last fired time, then printing “Attack {ActionIndex} in Frame {FrameIndex} Delta {Time since Last Fired}” or similar, after the delay node “Resetting Attack {ActionIndex} in Frame {FrameIndex} Delta {Time since Last Fired}”, (note don’t reget the variables you must execute them before the delay node, but printed after, so they match except the Delta which should use the current time. With this setup, the “Resetting Attack” should always appear between Attacks.

As to your hardware problem, I suspect you have misinterpreted whats actually happing; rather than getting multiple pressed events when you press the button, I suspect the debouncing circuit is faulty and when you release the button, the button is bouncing, so you sometimes get [Pressed, Button Held Down, Released, Pressed, Released], now if the length of Button Held Down exceeds your delay, or in your timer example the time fires during this period, you get to Attack, given the short time, you wouldn’t really be able to perceive these as separate events. To Check this I would suggest setting up a matching node group for the released event. Then, when the double firing occurs you should get [Attack Pressed, Attack Pressed Reset, Attack Released, Attack Pressed, Attack Released Reset, Attack Pressed Released] if this is the case.

2 Likes

Have u tried to use a different mouse and do it
Cause u told ur mouse double clicks it so try with another mouse