Stop friendly-fire between enemies

Screen shots would help. But from the sound of it, you seem to have the error of making your enemies children of the player character. So overlap events or hit events where you cast to “player character” will also fire if the child enemy is overlapping/hit.

Hello, I’m creating a game for practicing and learning porpuse. The thing is the enemies walk to me and attack but if another enemy is next to the one attacking me he get damaged too.

I tried to “filter” the attacker in the Apply Damage node by the Instigated by pin but I can make it work.

I have my character done in an actor BP and there is 2 types of enemies, that are childs of my character BP.

I someone needs I’ll post screenshots of my BP, just ask for what you need to see.

Yes, I know it’s not the best to create those childs. Here I attach 2 screenshots of the “SwordMesh” (where the sword damage is coded) and “ProyectilMesh” (where the magic damage is coded).

The Apply Damage node is coded on MyCharacterMesh.

Use PrintString to find out if your instigators are set correctly
When I look at the screen shoots sword has no instigator connected
when i look at the magic damage you take the controller of the instigator?
Is that instigator set correctly.

And this will apply damage, which you then need to filter out on the damage receiving side, something like this

That will not let any damage through done from a controller (your ai controller) to a same controller.
If you have multiple types of ai controller it’s a little bit more complicated, would suggest checking for player or Ai controller in that case

I had a similar concern and here is how I dealt with it (please note that I am a beginner with UE4 BP scripting as well) :

What I would do is have the base class (Character BP in your case it seems) have a boolean IsEnemy. Then your various implementation inheriting from your base class will set the boolean as true or false depending if it is an enemy, the player, a friendly npc…

Use the instigated by pin as you yourself suggested and get that IsEnemy boolean and compare it to the class that is hit. If they are not both enemies or both allies, proceed to apply damage.

That looks a bit like this (in my case they all are GameCharacter's and this class has the IsEnemy boolean) :

You could encapsulate it in a function you call each time you try to deal damage and bypass it for the events for which you don’t want to ignore friendly fire but that may be out of scope of the question.

I would recommend that you do NOT make your enemies inherit from your (Player)CharacterBP (as it seems to be the case currently if I understood well) but rather from a neutral class both your PlayerCharacter and your EnemyCharacter would inherit. It would work anyway but that design may limit your options and cause trouble later.

Hello I had the same problem with my AI dealing damage to one another when trying to shoot me. This is how I solved it.

Top part is for projectile the bottom part is inside my AI’s blueprint.

Projectile passes over the Controller responsible for firing a projectile. When receiving damage the AI checks is Player is the instigator and when true damage is being applied. Crude but works for me.

Newbie style coding, sowwy.

Well, this last answer hit the nail. I added a instigator in the “sword” BP calling the “Instigator” actor variable and pass it to “get controlled pawn”.

Then I added your code in my 2 childs BP and it worked like a charm.

You’re a god, I spent 2 days trying to make it work but I couldn’t. I was comparing classes like you suggest but for some reason I was failing.

Hey guys, I already found an aswer that is currently working (Lardo Deepdelver provided it) but I just want to say thank you for taking your time and trying to help me.