Main Character Attacks Self When Attacking?

okay. my main character takes damage when she hits my enemy… sometimes… can I somehow in the weapon BP be like

if (attacked actor == self)
{
do not damage
}

or

ActorsToIgnore.Add(OwningActor)

in the weapon BP like that it gets implemented to whoever is holding a weapon?

Ps: I do enable and disable box collision

Main Character ABP

MainCharacter AM

Main Character Mesh Collision

Weapon Box Collision

Weapon Mesh Collision

Add your character to Ignore Actor when Moving for the weapon.

if you are using c++ then you can use owning actor. But be sure that the player character owns the weapon.

It won’t be set by default so call setOwner() on the weapon once you spawn the weapon and assign the character as the owner to be sure.

Then you can rely on passing in the owner.

well in the past I had tried something, because my character does not own the weapon.

in weapon.h, I did this
UPROPERTY()
TArray<AActor*> IgnoreActors;

and then in the character who collects the weapon when pressing the E key, I did this.

but it doesn’t work.

I think that it would have to go in my take damage function though right?

You should use the ignore code for the weapon collision box

example where WeaponBox is a uboxcomponent collider for the weapon:

WeaponBox->IgnoreActorWhenMoving(MyCharacter,true);

And do this only once when equipping / unequipping not every time you attack.

so this is what I have so far, but it still doesnt work.

sometimes itll even hit both the enemy and me.

Is this a single player or multiplayer game? If it’s MP then you need to set these parameters only on the server not the client.

Try printing out the actor ignore list for your weapon when it detects a hit (loop though the ignore list and see if your player character is present there). Perhaps it’s being reset somewhere else in the game?

okay I didn’t think about it clashing together… i do have this in here.

It would probably best it you unify the ignore list for both traces and collisions in this case.

YES!! it worked!! I passed in get owner instead of actor!! :slight_smile: thank you!! again!! :)!!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.