Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

how disable a projectile hit to self pawn

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"
 class PISTOLWEAPON_API ABullet : public AActor
     UPROPERTY(VisibleDefaultsOnly, Category = Customize)
     TSubobjectPtr<USphereComponent> sphereCollision;
     UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Customize)
     TSubobjectPtr<UProjectileMovementComponent> projectileMovement;
     void OnHit(AActor* otherActor, UPrimitiveComponent* otherPrimitiveComponent, FVector normalImpluse, const FHitResult& hitResult);
     void SetSelfPawn(APawn* selfPawn);
     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->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());
 void ABullet::SetSelfPawn(APawn* selfPawn)
     this->selfPawn = self

Product Version: Not Selected
more ▼

asked Sep 01 '14 at 02:27 AM in C++ Programming

avatar image

22 7 7 11

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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.

more ▼

answered Sep 01 '14 at 03:22 AM

avatar image

3.4k 154 51 271

avatar image mohammadali1375 Sep 01 '14 at 03:55 AM

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

avatar image mindfane Sep 01 '14 at 05:09 AM

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). https://docs.unrealengine.com/latest/INT/API/Runtime/Engine/Components/UPrimitiveComponent/IgnoreActorWhenMoving/index.html

So right after spawning the projectile, do this:


Also do the opposite in your Players code:


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

avatar image mindfane Oct 20 '14 at 07:41 AM

I am assuming the issue is solved.

avatar image Anorian Nov 21 '14 at 02:49 PM

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?

avatar image mindfane Nov 25 '14 at 03:43 PM

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.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question