Toggle on/off looping auto attack

Hello everybody! I am a couple weeks into learning UE5 on my own and I have a simple question that I may not be understanding how things work on UE5 and would like some feedback input.

Problem: If I press “Q” my pawn will loop an animation montage using “Set Timer by Function Name.” I would like for the looping to continue until the player presses “Q” until the looping stops. Below are screenshots of the function I have now.

Any help would be appreciated!

Additionally, I had “set AA Stop” on to try to stop the loop but that turned out to not function the way I expected… I may be misunderstanding the way the looping boolean part of set timer. I removed all of my previous solutions since nothing worked properly.

If you use the boolean like you are now, you can do something like:

Input 
if not AAActive
    then:
         Set Timer -> Save return value to variable (named for example AATimer)
         Set AAActive to true
    else:
         Get AATimer -> Clear and invalidate timer
         Set AAActive to false

That’s all you should need, and then the Auto Attack function doesn’t need the branch
Also, perhaps you could change your timer’s rate to be your attack cooldown instead of 1 second

You can also use a Flip Flop to avoid having to use a boolean
A flip flop just alternates between the two states, so first time execution reaches the node A will be executed, second time B will be executed, then A, then B and so on

1 Like

@zeaf Appreciate the help! I tried to implement both solutions you suggested and ended up using the Flip Flop function which was more aligned to what I wanted to do.

Sadly, the execution is still off a bit. The problem That I was trying to fix now is that the code seems to only work some of the time. I have attached a video of the code and an video of how it only works some of the time now.

Could you further assist when able?

I have the function print text in the top left every time I press Q for review purposes.

NVM I switched the Flip Flop function to the “started” output instead of the “triggered” and everything works perfectly now.

Thanks for all the help @zeaf !!

Attached is the final solution:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.