How do I get my character to auto attack?

Hi! I’ve tried adding a “WhileLoop” after the rotation, with the condition basically being that I attack until AI health is <=0, but it just results in an infinite loop error or engine crash.

Any help or guidance is appreciated

Have you tried calling the event directly from tick (this would not be performant) just to test if it works?
If it is working correctly, then try adding a collision sphere around your character to reach out to the range you want player to attack. Then, play your anim montage and deal damage when an object overlaps it (you could set up a custom collision channel just for this if you wish)

I’ve set it up with the tick and collision and it looks like it could/will work. But because of the tick, it’s only playing the first frame of my animation, so I can’t move or do anything else. Without the tick, it only plays the animation once, then I have to move away, come back, to retrigger the collision event.

Ty for your help so far.

  1. What do you mean by “auto” attack? You want it to “auto” play the animation?
  2. Can you post an actual image attachment, this pic is pretty bad and what is beyond the gate?
  3. Screen shots of the rest of your set-up would be helpful

Auto attack meaning, moving within range of the enemy and the montage looping until the enemy is dead. At the moment, with the event tick plugged it, it just plays the first frame of the montage constantly, with it out, it only plays the montage once.

I’ve attached a new screenshot. The event tick goes into the “Enter” on the gate.


I am not familiar with montages, BUT if you are running that on tick I am pretty sure it is trying to “Play” the montage from the start each frame hence even though it may be doing the rest of it underneath, it is constantly being asked to start a new montage each frame, so each frame it plays from the beginning. Maybe instead of “tick” use a timeline, that has a loop function built in, so you can set an event graph in the timeline and it will execute once every “X” seconds that you tell it to, so, determine the length of the montage and set that to the internal timeline length and tell it to loop.

Thank you! This is perfect and versatile for use with other interactions. Also, thank you to the others who replied, I took points from all 3 and now I have a better idea on how to improve a lot of my blueprints. :slight_smile:

Hi. Instead of WhileLoop I will create Attack_Function that will hold all animation calling(you can call montage again once it finished playback) then use SetTimerByFunctionName (Attack_Function) in Character_BP to activate this function when conditions necessary for attack are true. Deactivate Timer if conditions are not true. Does this sound fit?

1 Like

this is fine, this means that your setup is working. on event “begin overlap” of that collision sphere, play the animation with “looping” set in properties. then on event end overlap, stop playing the animation. if you want to check if the player that youre attacking is dead, add a branch before playing the animation checking a boolean if the enemy is alive or not (cast to enemy, get boolean (isalive) or something like that

Glad to hear you got it sorted, cheers