So I got a very simple line trace to test physical material and custom surface type, basically what it does is to trace object of type Pawn and Player(custom type I added), and depending on the sufaceType I gave them on their physical material I overrided in the details pannel, I print different infomations on the screen:
TArray hitResults;
EObjectTypeQuery Player = UEngineTypes::ConvertToObjectType(ECC_Player);
EObjectTypeQuery Pawn = UEngineTypes::ConvertToObjectType(ECC_Pawn);
//objectType to trace.
TArray<TEnumAsByte<EObjectTypeQuery>> ObjectQueryParams;
ObjectQueryParams.Push(Player);
ObjectQueryParams.Push(Pawn);
FCollisionQueryParams QueryParams("Detection", false, this);
QueryParams.bTraceAsyncScene = true;
QueryParams.bReturnPhysicalMaterial = true;
bool bIsHit = GetWorld()->LineTraceMultiByObjectType(hitResults,
GetActorLocation(),
GetActorLocation() + GetActorForwardVector() * 10000,
FCollisionObjectQueryParams(),
QueryParams
);
if (bIsHit)
{
for (FHitResult Hit : hitResults)
{
UPhysicalMaterial* PhysicsMtl = Hit.PhysMaterial.Get();
if (PhysicsMtl->SurfaceType == SurfaceType_Default)
{
FString NameOfHitedObject = Hit.GetActor()->GetName();
if (GEngine)
{
GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Red, "I see a Normal: " + NameOfHitedObject);
}
}
if (PhysicsMtl->SurfaceType == SURFACE_FANCY)
{
FString NameOfHitedObject = Hit.GetActor()->GetName();
if (GEngine)
{
GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Red, "I see a FANCY: " + NameOfHitedObject);
}
}else if (PhysicsMtl->SurfaceType == SURFACE_UGLY)
{
FString NameOfHitedObject = Hit.GetActor()->GetName();
if (GEngine)
{
GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Red, "I see a FANCY: " + NameOfHitedObject);
}
}
}
}
this will work on if I set bInTraceComplex to false in the FCollisionQueryParams. otherwise, I got default surfaceType on everything it hit regardless of the actaully sufaceType I gave them…
Cound any one help me please?
Thanks in advance.