[Collision] Overlap information

Hey guys,

I’m trying to get additional Information from the OnComponentBeginOverlap event, but the method I’m using (void ASomeCharacter::OnBeginOverlap(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult & SweepResult)) doesn’t really tell me a lot about WHERE the overlap begins and stuff like that.

I’d love to get some information about the overlapping volume / location at any time, but I want at LEAST the location when the overlapping takes place for the first time …

The SweepResult doesn’t return anything though (every attribute is set to default) and the bFromSweep bool is always set to false so I don’t get any information from that!
I’m happy about every idea I can get, so thanks in advance!

Have a nice day,

I’m experiencing the same issue with 4.10
Did you ever find a solution to this?

I’m not seeing that happen. SweepResult.Location has the original overlapping location for me (I’m also in 4.10). What I have in MyCharacter.cpp:

In the constructor:

GetCapsuleComponent()->OnComponentBeginOverlap.AddDynamic(this, &AMyCharacter::OnOverlapBegin);

The delegate body:

void AMyCharacter::OnOverlapBegin(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult) {
    DrawDebugSphere(GetWorld(),
    SweepResult.Location,
    16,32,FColor(255, 0, 0),false,3.0f);
}

OnOverlapBegin is set as a UFUNCTION

As I’m having the same issue, here’s what I’m doing.

Note that I’m extending AActor.

My header file has the following:

UFUNCTION()
    void OnBeginOverlap(AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult & SweepResult);

And my cpp file has this:

In the constructor:

SpriteComponent->OnComponentBeginOverlap.AddDynamic(this, &AMob::OnBeginOverlap);

And then the function is just this. It’s being called but the hit information is empty:

void AMob::OnBeginOverlap(AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult & SweepResult)
{
    if (OtherActor != this) {
        UE_LOG(LogTemp, Warning, TEXT("OnBeginOverlap"));
        FVector Location = GetActorLocation();
        
        if (!SweepResult.bStartPenetrating) {
            GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, FString::Printf(TEXT("Distance: %f"), SweepResult.Distance));
            GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, FString::Printf(TEXT("Pene: %f"), SweepResult.PenetrationDepth));
            GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, FString::Printf(TEXT("Loc: %f %f %f"), SweepResult.Location.X, SweepResult.Location.Y, SweepResult.Location.Z));
            Location.Z += SweepResult.Distance;
            GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, FString::Printf(TEXT("Imp: %f %f %f"), SweepResult.ImpactNormal.X, SweepResult.ImpactNormal.Y, SweepResult.ImpactNormal.Z));
            Location.Z += SweepResult.Distance;
        } else {
            GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, FString::Printf(TEXT("Pene: %f"), SweepResult.PenetrationDepth));
            Location.Z += SweepResult.PenetrationDepth;
        }
        SetActorLocation(Location);
    }

}

Please note that I’m using Paper2D and that my collider is drawn on the SpriteComponent. I don’t know if that might be a problem.

The full test code can be found there if you want to have a look at it: GitHub - tanis2000/Unreal-Test2DPlatformer: A test project for a 2D platformer built with Unreal Engine 4

If you’re working with Sprites, you have to add collision and click “Generate Overlap Events”. If you add a BOX or Sphere component to your blueprint and use it to fire the overlap events it will work fine. You just make it the ROOT for the blueprint and configure its shape.

Also if you have a static mesh WITHOUT a collision mesh it will not generate hit, overlap or any triggerable events.