Is this a correct way of using a blueprint interface?

Hi! For my game I stumbled upon an issue when my player slashed at an enemy. I eventually did a really crappy workaround where I made a variable called “Attacking” and made it true for 1/10th of a second, and if the player overlapped the enemy while slashing and that variable was true then it ran the hurt/hit function.

So what I did recently was create an interface called “Attacking” and implemented it onto the player and all the enemies. Inside I placed a function called “Slashing”. In the slash event for the player I made it so that it fired that function for every actor that has it implemented, and then inside of the enemy’s bp it would check if the player is within range, and if it is then do the hurt/hit.

Would this be a correct way of using an interface? Is this any costly? The reason why I didn’t have the player just cast to the enemy and fire the hit event manually is for a few reasons, but I think that’s besides the point :slight_smile:

Thank you!

This seems like an odd way to implement a slash mechanic. Depending on the way your system is going to work i would maybe think of something like:

  1. Do a box trace in front of character and return all hit actors of correct collision/trace channel. This would be triggered by either a timer or an animation notify to tell you the proper point in the swing to check.
  2. Actually detect if the weapon overlaps a mesh after setting Attacking to true.
  3. Build a custom collision component and check it for overlapping at the time of attack.

Otherwise that is a proper way to use an interface. Interfaces guarantee the a function will exist so its definitely a way to tell if something is what you are looking for. They are kind of crappy at sharing functionality though. If you want some shared functionality then components or parent classes may be the way to go depending on your situation.

Thanks! I don’t really care about shared functionality; in fact I want each function to perform differently. I actually already did all that, but an issue with “Attacking” being set to true is that it stays true for too long, so sometimes the damage function fires more than once >.< Using interfaces I get one guaranteed output; just like if I were using input events.

Whoops! forgot to say my game is a 2D platformer; there are no anim notifies with Paper2D, I believe.

Oh hmmm, I really have no experience with Paper2D.

Could you:

  1. Check to see if you are overlapping another sprite
  2. Verify the hit sprite is in front of the character
  3. Check the hit sprites interface

I guess in the end it matters if you want to have continuous detection or a single moment of detection at the top of the slashes arch.