Turn OnSeePawn on and off?

  • I want to make a very simple melee attack Ai without the use of Ai behaviour trees.

  • In my blueprint Ai starts with an OnSeePawn, moves to actor location when activated, when in range of less than 200 it plays an animation(that lasts 2 seconds) and applies damage.

  • My idea is that now it should check for range again and repeat the cycle and either move to actor or attack it and deal damage.

  • The Problem is that OnSeePawn keeps ticking and it can not play animation without resetting everything

  • Is there a way to fire off OnSeePawn when it first sees the character and then turn it off(and maybe turn it on again under specific conditions)?

I’ve done something similar in my game. Here’s a basic system:

  1. Create 2 variables: a bool, “isAttacking”, and a pawn variable, “Target Actor”.
  2. When it sees a character/pawn, (add a check here, IF isAttacking is false) set isAttacking to true and the target actor to the character/pawn reference. Then move towards the player.
  3. On Event Tick, you can add 2 checks. First, if isAttacking is true, then check: If Target Actor is valid (if you are in a multiplayer game, maybe the player disconnect), and if the target is within range/still visible by running a line trace or something.

That should be enough for now, you can certainly add more checks/functionality later on.