How disable a projectile hit to self pawn

I am not sure what you are trying to achieve here. But I assume you want to destroy a projectile when it hits the player character?

What I would do here is add an OnBeginOverlap event on the projectile. I will then try to cast the ‘otherActor’ param to the player character class. If that succeeds, you can check it against the stored ‘selfPawn’ variable and destroy the projectile (or anything else you want) if they are the same.

Hi. I have a projectile.
but I want dont do any special action when hit to owner pawn how shoot it
how can I do this ?

( I use pawn location to check but It just dont destroy it, but set projectile’s speed = 0)

#pragma once

#include "GameFramework/Actor.h"
#include "Bullet.generated.h"

/**
 * 
 */
UCLASS()
class PISTOLWEAPON_API ABullet : public AActor
{
	GENERATED_UCLASS_BODY()

	UPROPERTY(VisibleDefaultsOnly, Category = Customize)
	TSubobjectPtr<USphereComponent> sphereCollision;
	
	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Customize)
	TSubobjectPtr<UProjectileMovementComponent> projectileMovement;

	UFUNCTION()
	void OnHit(AActor* otherActor, UPrimitiveComponent* otherPrimitiveComponent, FVector normalImpluse, const FHitResult& hitResult);
	
	UFUNCTION()
	void SetSelfPawn(APawn* selfPawn);

private:

	APawn* selfPawn;

};

#include "PistolWeapon.h"
#include "Bullet.h"
#include "GameFramework/ProjectileMovementComponent.h"

ABullet::ABullet(const class FPostConstructInitializeProperties& PCIP)
	: Super(PCIP)
{
	sphereCollision = PCIP.CreateDefaultSubobject<USphereComponent>(this, TEXT("SphereCollision"));
	sphereCollision->InitSphereRadius(1);
	sphereCollision->BodyInstance.SetCollisionProfileName("Projectile");
	sphereCollision->OnComponentHit.AddDynamic(this, &ABullet::OnHit);
	RootComponent = sphereCollision;

	projectileMovement = PCIP.CreateDefaultSubobject<UProjectileMovementComponent>(this, TEXT("ProjectileMovement"));
	projectileMovement->UpdatedComponent = sphereCollision;
	projectileMovement->InitialSpeed = 1000;
	projectileMovement->MaxSpeed = 1000;
	projectileMovement->bRotationFollowsVelocity = true;
	projectileMovement->bShouldBounce = false;
	projectileMovement->ProjectileGravityScale = 0;
	InitialLifeSpan = 1;

}

void ABullet::OnHit(AActor* otherActor, UPrimitiveComponent* otherPrimitiveComponent, FVector normalImpluse, const FHitResult& hitResult)
{
	if (selfPawn->GetActorLocation() != otherActor->GetActorLocation())
	{
		otherPrimitiveComponent->AddImpulseAtLocation(GetVelocity() * 100, GetActorLocation());
		Destroy();
	}
}

void ABullet::SetSelfPawn(APawn* selfPawn)
{
	this->selfPawn = self
}

oh. I’sorry, my english is not good
when I turn my weapon from up to down ( in first person view) the MuzzelFlash socket become in player capsule collision and the projectile will be remove
I dont want happen this. I want shoot normal when the projectile become to own player collider

Ok, I think I understand you now. So you want to prevent your projectile from colliding with your own Player. Thats pretty simple there is a function called ‘IgnoreActorWhenMoving’ defined in the Component class. SO when you fire your projectile, get a reference to its collision component and add your Player into the list of Ignored Actors. You could do the opposite for your Player as well (ie add the projectile into the list of ignored actors for your player’s collsion component).

So right after spawning the projectile, do this:

projectile->sphereCollision->IgnoreActorWhenMoving(&this);

Also do the opposite in your Players code:

this->capsuleComponent->IgnoreActorWhenMoving(projectile)

NOTE: I did not test this code, so there might be syntax errors. So double check the code.

I am assuming the issue is solved.

If I may high jack this thread somewhat please: The above info is just what I was looking for too. Great. One additional question though if I may: what about a networked scenario? Will calling “'IgnoreActorWhenMoving()” on a projectile spawned on the server also replicate this setting in some form so that there will also be no collissions on the client?

I think its depends on who the owner is. If both Actors are spawned on the server (ie The gun and the projectile), it will work as expected since the client will simply be replicating the position from the server. If both are spawned on client instead, same logic applies.

But if one of them is spawned at server and the other on client, then I am not quite sure. I haven’t tried that yet and unfortunately I cannot test it anytime soon. But I would say it might not work.