Hit event fires too late

Hey Guys,

I am coding on a solution to add a second collider to my character. I created a second actor which follows the main character and moves exactly the same way. This actor has the second collider. During my characterMovement I check the settings of the second collider and decide wether my character is allowed to move. This works out better than expected so far, but the second collider fires the hit event too late. The collider is already hitting another object, but the event firest only after the collider moves a ceratin depth into the other object. I want the event as soon as the collider hits another object. Any ideas?

Cheers

Hm, that sounds weird. Would you mind showing me your setup? I would need a picture of the collider settings, maybe the hit event and if possible a screen of the exact depth it takes to fire the event. Maybe i can find the source of this problem (:

Hi,

thx for the answer. The collider is setup in code:

   ASecondCollider::ASecondCollider(const FObjectInitializer& ObjectInitializer)
	: Super(ObjectInitializer)
{

	// Create Second Collider
	SecondCapsuleComponent = ObjectInitializer.CreateDefaultSubobject<UCapsuleComponent>(this, TEXT("SecondCollider"));
	
	MovementComponent = ObjectInitializer.CreateDefaultSubobject<USecondColliderMovementComponent>(this, TEXT("MovementComponent"));
}


void ASecondCollider::PostInitializeComponents(){

	Super::PostInitializeComponents();

	SecondCapsuleComponent->InitCapsuleSize(70.0f, 170.0f);

	// Only for debuggin, later invisble
	SecondCapsuleComponent->SetHiddenInGame(false);
	SecondCapsuleComponent->SetVisibility(true);

	SecondCapsuleComponent->SetCollisionEnabled(ECollisionEnabled::QueryAndPhysics);
	SecondCapsuleComponent->SetCollisionObjectType(ECollisionChannel::ECC_Pawn);

	SecondCapsuleComponent->SetCollisionProfileName("SecondCollider");

	if (MovementComponent)
	{
		MovementComponent->UpdatedComponent = SecondCapsuleComponent;
	}
}

void ASecondCollider::ReceiveHit(class UPrimitiveComponent* MyComp, AActor* Other, class UPrimitiveComponent* OtherComp, bool bSelfMoved, FVector HitLocation, FVector HitNormal, FVector NormalImpulse, const FHitResult& Hit){
	GEngine->AddOnScreenDebugMessage(-1, 25.f, FColor::Red, FString::Printf(TEXT("Hit!!! ")));
}

These are my collision settings:

Hm, to be honest, i have no idea right now what could be wrong.

The big collider is your second collider, right? What is the objects type that you try to run into? Did you enable “Simulation Generates Hit Events” on both actors?

Would you mind trying “Event Actor Begin Overlap” instead of “Event Hit”. Normaly the Hit Event fires if both Acots have the generation enabled. The Overlap Event though only needs the actor that executes the event to have “Generate Overlap Events” enabled.

Maybe it is just a problem of how you want to use it :X

I hope this helps somehow.

In addition: Have you tried calling the Event Hit from the Blueprint? Just for debuggin you know x)

Finally found the solution :slight_smile:
I was calling InitCapsuleSize instead of SetCapsuleSize
So my guess is that the capsule already had an InitialSize and somehow didnt update the collision behavior to the new size only the collider view inside the game.
Still a little bit strange somehow, but at least my problem is sovled.

1 Like

Uff ok xD Didn’t know there was a difference. Have looked them up in the API. Seems like the Set is changing it after it has been initialized. But the Init Part isn’t really documented: