Have player character take damage only within range

I’ve been playing around with the new damage system Unreal has provided, everything works just like it’s supposed to. My only question is that how would I have my character take damage only when the player character is within a limited range and not have the A.I play it’s attack animation from across the map and have the player character take damage. I want my player character to be in front of the A.I for it to take damage. I tried, but it is not working for me

What kinda damage is your AI doing? Ranged? Melee? AoE?

A simple Melee attack, the A.I runs up to the player character and swings for one punch.

Link the Get Distance To pin to Damage Causer instead of Instigated By. However, I strongly urge you to NOT implement this check here. The range check should be on Damage Causer. Check the range there, and apply damage only when in range.

Doing so will allow you to easily change melee range weapons (dagger is shorter than a lance) and allow you to implement other weapons later (bows, guns, etc)

Thank you for helping, the way I set it up is. If the player character is in range of the A.I, the player character will take damage. But if the player character isn’t in range, the A.I will just continue to do what it was going to follow through on and the player character won’t take any damage.

I did so in the A.I character’s blueprint

You might want to implement this with Behavior Trees. Have a read through this. It’s OK to have the core logic in the character blueprint, but you really want to drive the “thinking” part via Behavior Trees.