# Only one OnComponentHit event is firing

**URL:** <https://forums.unrealengine.com/t/only-one-oncomponenthit-event-is-firing/456675>\
**Category:** World Creation\
**Tags:** oncomponenthit, unreal-engine, Physics, Collision, question, actor-class\
**Created:** [October 9, 2019, 12:08pm UTC](https://forums.unrealengine.com/t/only-one-oncomponenthit-event-is-firing/456675 "2019-10-09T12:08:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![morbal](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@morbal](https://forums.unrealengine.com/u/morbal)\
**Post date:** [October 9, 2019, 12:08pm UTC](https://forums.unrealengine.com/t/only-one-oncomponenthit-event-is-firing/456675/1 "2019-10-09T12:08:36Z")

</div>

i have two types of arrows which are defined and spawned in character controller as follows:

```
character.h file:
	UPROPERTY(EditAnywhere,BlueprintReadWrite, Category = Projectile)
		TSubclassOf<class AArrowProjectile> NormalArrowClass;
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Projectile)
		TSubclassOf<class ASpeicalArrow> SpecialArrowClass;

Character.cpp file:
			switch (SelectedArrowNumber){
			case 0:
				World->SpawnActor<AArrowProjectile>(NormalArrowClass, SpawnLocation, SpawnRotation, ActorSpawnParams);
				break;
			case 1:
				World->SpawnActor<ASpeicalArrow>(SpecialArrowClass, SpawnLocation, SpawnRotation, ActorSpawnParams);
				break;
			default:
				World->SpawnActor<AArrowProjectile>(NormalArrowClass, SpawnLocation, SpawnRotation, ActorSpawnParams);
				break;
			}

```

each one has a separate actor type class where i have defined a static mesh and a sphere collider for them  
im trying to activate hit even for them but only the first one is activating

ArrowProjectile.h

```
    // Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "ArrowProjectile.generated.h"

UCLASS()
class TESTSHOOTER_API AArrowProjectile : public AActor
{
	GENERATED_BODY()
		
	UPROPERTY(VisibleDefaultsOnly, Category = Projectile)
		class USphereComponent* CollisionComp;
	
	UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = Movement, meta = (AllowPrivateAccess = "true"))
		class UProjectileMovementComponent* ProjectileMovement;
	UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = Mesh, meta = (AllowPrivateAccess = "true"))
		class UStaticMeshComponent* ArrowMesh;
	UPROPERTY(EditDefaultsOnly, Category = Default)
		AActor* PlayerActorBlueprint;
	
		
public:	
	// Sets default values for this actor's properties
	AArrowProjectile();
	protected:
		UFUNCTION()
		void OnHit(UPrimitiveComponent* HitComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit);

public:	
	

	/ **Returns CollisionComp subobject** /
	FORCEINLINE class USphereComponent* GetCollisionComp() const { return CollisionComp; }
	/ **Returns ProjectileMovement subobject** /
	FORCEINLINE class UProjectileMovementComponent* GetProjectileMovement() const { return ProjectileMovement; }

	
};

```

ArrowProjectile.cpp

```
   // Fill out your copyright notice in the Description page of Project Settings.

#include "ArrowProjectile.h"
#include "GameFramework/ProjectileMovementComponent.h"
#include "Components/SphereComponent.h"

// Sets default values
AArrowProjectile::AArrowProjectile()
{
	
	// Use a sphere as a simple collision representation
	CollisionComp = CreateDefaultSubobject<USphereComponent>(TEXT("SphereComp"));
	CollisionComp->InitSphereRadius(5.0f);

	// Players can't walk on it
	CollisionComp->SetWalkableSlopeOverride(FWalkableSlopeOverride(WalkableSlope_Unwalkable, 0.f));
	CollisionComp->CanCharacterStepUpOn = ECB_No;
	CollisionComp->OnComponentHit.AddDynamic(this, &AArrowProjectile::OnHit);
	ArrowMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Arrow Mesh"));
	ArrowMesh->SetupAttachment(CollisionComp);

	// Set as root component
	RootComponent = CollisionComp;

	// Use a ProjectileMovementComponent to govern this projectile's movement
	ProjectileMovement = CreateDefaultSubobject<UProjectileMovementComponent>(TEXT("ProjectileComp"));
	ProjectileMovement->UpdatedComponent = CollisionComp;
	ProjectileMovement->InitialSpeed = 5000/1.2f;
	ProjectileMovement->MaxSpeed = 5000*1.2f;
	ProjectileMovement->bRotationFollowsVelocity = true;
	ProjectileMovement->bShouldBounce = false;

	// Die after 3 seconds by default
	InitialLifeSpan = 3.0f;
	
	
}

void AArrowProjectile::OnHit(UPrimitiveComponent* HitComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit)
{

	GEngine->AddOnScreenDebugMessage(-1, 2.0f, FColor::Red, TEXT("Normal Arrow Hit"));

	// Only add impulse and destroy projectile if we hit a physics
	if ((OtherActor != NULL) && (OtherActor != this) && (OtherComp != NULL) && OtherComp->IsSimulatingPhysics())
	{
		OtherComp->AddImpulseAtLocation(GetVelocity() * 100.0f, GetActorLocation());

		Destroy();
	}
}

```

the SpeicalArrow class uses exactly the same code the only difference is wherever there is ArrowProjectile or AArrowProjectile i changed it to SpeicalArrow or ASpecialArrow and changed the Gengine-\>… messages

so when i fire the normal arrow i get the “Normal arrow spawned” and “Normal Arrow Hit” message  
but when i fire second arrow i only get “Special Arrow Spawned” message so the OnHit(…) function is not running.  
both arrow are using the same collision preset and object type

---

<div class="post-metadata">

**Author:** ![morbal](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@morbal](https://forums.unrealengine.com/u/morbal)\
**Post date:** [October 9, 2019, 12:27pm UTC](https://forums.unrealengine.com/t/only-one-oncomponenthit-event-is-firing/456675/2 "2019-10-09T12:27:08Z")

</div>

it is basically the same Projectile class from FPS sample of unreal.  
i haven’t mentioned some other code from my Character class as i thought they aren’t needed, please tell me if you need the code

---

<div class="post-metadata">

**Author:** ![FaridSulejmani](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@FaridSulejmani](https://forums.unrealengine.com/u/FaridSulejmani)\
**Post date:** [October 9, 2019, 2:43pm UTC](https://forums.unrealengine.com/t/only-one-oncomponenthit-event-is-firing/456675/3 "2019-10-09T14:43:17Z")

</div>

put  
CollisionComp-\>OnComponentHit.AddDynamic(this, &AArrowProjectile::OnHit);  
in your BeginPlay() function
