How do I stop the enemy AIs from damaging each other using SphereTraceByChannel?

I’m using a SphereTraceByChannel in an AnimNotifyState to let the player and enemy deal damage, which works fine for dealing damage, but I noticed that the enemies also damage each other instead of just the player whenever they get too close to each other and attack. How can I prevent the SphereTrace from tracing the other enemies?

Here are the blueprints for the enemy AI damage AnimNotifyStates:

NotifyBegin

NotifyEnd

NotifyTick

Hum my quick take on it would be that your Actor to ignore array is empty. Try feeding the actor you want to avoid into it.

Alternatively you could use tags and check if the actor has the tag before applying damage.

For example in you enemy blueprint, you would drag out of your Out Hit Actor (in the Sphere trace) and use the Has Tag node. Add a Player Tag in your Player BP and choose this tag in the Has Tag node. This will make sure that your enemy can only damage the Player or any actors that have the Player tag you created.

Hopefully this can help you !! Good luck !

Hey there @iEnzoVer.MOBIUS! Welcome to the community! So I would personally recommend using Sphere Trace for Objects instead of Sphere Trace by Channel.


(Instead of enemies, you’d make a player/playerObjects channel in project settings)

As it will allow you to select only the collision channels you’d like to check at all instead of all that can be hit via the camera trace. Technically you could process the hits and check for tags or compare classes afterward, but to save a bit of effort, it might be easier to just make a collision channel for just player objects.

I tried this, but for some reason nothing is being traced, and even when I set the draw debug type to duration nothing appears either. I also changed the players mesh and capsule collisions object type but that doesn’t seem to work as well. Am I misunderstanding something?

Here’s a screenshot of the changes with the blueprint:

EDIT: Never mind its working now for some reason after I reopened the editor.

you can use interfaces. a really simple setup would be to have to interface iGamePlayer and iGameEnemy. then you check if the trace result implements the interface you want and act accordingly.

I’m assuming you want to have one single blueprint that works both on player and npc? a universal setup?

you could check if the other character implements same interface as the one that cast it. if is the same then you don’t apply the damage

note: I’m no expert at this and there may be a easier method