Download

ImpactPoint of HitResult sometimes returns the correct value, most of the time returns the origin?

To put it simply, I have a StaticMeshComponent sphere which when it overlaps with another actor, needs to get the impact point from the FHitResult. When a player overlaps with the sphere, it usually returns the ImpactPoint as expected, however most of the time with any actor, it simply returns the world origin (0, 0, 0) as the impact point.

I have tested this with debug messages, line traces e.t.c and I can’t find a cause anywhere. I will happily attach screenshots if anyone would like them, and I’ll post the section of the code below.

If anyone has a faint idea of what could be causing this please let me know, I can’t seem to solve this one myself. Cheers.

Here is the full function, I have put the important parts in bold.

void ABoid2::OnOverlapBeginSensor(UPrimitiveComponent * OverlappedComp, AActor * OtherActor, UPrimitiveComponent * OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
if (OtherActor->GetClass() == this->GetClass())
{
if (OtherActor != this)
{
if (OtherComp->GetName() == TEXT(“Body Mesh”))
{
GEngine->AddOnScreenDebugMessage(-1, 15.0f, DebugColor, TEXT(“Attract”));
BoidLocations.Add(OtherActor);
BoidVelocities.Add(FVector(OtherActor->GetVelocity()));
}
}
}
else
{
GEngine->AddOnScreenDebugMessage(-1, 15.0f, DebugColor, TEXT(“Repelling Not Boid”));
FVector Impact = SweepResult.ImpactPoint;
GEngine->AddOnScreenDebugMessage(-1, 15.0f, DebugColor, Impact.ToString());
RepulsiveLocations.Add(Impact);
RepulsiveActors.Add(OtherActor);
DrawDebugLine(GetWorld(), Location, Impact, FColor::Orange, false, 10.0f);
DrawDebugBox(GetWorld(), Impact, FVector(5, 5, 10), FColor::Cyan, false, 10.0f);
}
}