Dear all, I am trying to detect a hit using a SphereTraceSingle
inside my character’s Tick()
.
When I put other characters, it detects correctly the hit, but if I create a Blueprint for random objects in the scene it does not detect anything.
I have tried ECC_WorldDynamic
, ECC_WorldStatic
… I have tried to put a static mesh inside the BP, a dynamic one, a static as a child of the dynamic…
Maybe I am missing some BP settings here that prevent a collision?
I am attaching the settings of my BP actor, which I am changing trying to find the faulty setting, and my code…
Any help is greatly appreciated!
FHitResult HitResult;
FCollisionQueryParams CollisionParams;
CollisionParams.AddIgnoredActor(this);
CollisionParams.bTraceComplex = true;
float SphereRadius = 50.0f;
FVector StartLocation = GetActorLocation() + GetActorForwardVector() * 150.0f;
FVector EndLocation = StartLocation + GetActorForwardVector() * 500.0f;
ETraceTypeQuery TraceType = UEngineTypes::ConvertToTraceType(ECC_WorldDynamic);
bool IsHit = UKismetSystemLibrary::SphereTraceSingle(
GetWorld(),
StartLocation,
EndLocation,
SphereRadius,
TraceType,
false,
TArray<AActor*>(),
EDrawDebugTrace::ForOneFrame,
HitResult,
true
);
// if we hit something and it's interactable
if (IsHit)
{
GEngine->AddOnScreenDebugMessage(0, 5.0f, FColor::Black,
FString::Printf(TEXT("can interact with %s"), *HitResult.GetActor()->GetActorNameOrLabel()));
DrawDebugSphere(GetWorld(), HitResult.ImpactPoint, SphereRadius, 12, FColor::Magenta, false, 1.0f);
InteractableActor = HitResult.GetActor()->GetClass()->ImplementsInterface(UTOWInteractable::StaticClass()) ? HitResult.GetActor() : nullptr;
}
else
{
//GEngine->AddOnScreenDebugMessage(0, 10.0f, FColor::Black,
// FString::Printf(TEXT("cannot interact with anything")));
InteractableActor = nullptr;
}