PhysicalMaterial Crash when reading the name

Hi,

I have a .fbx road, which have materials different for each part of the road.
I want to know the hit material name when using a line trace.

So I have this code:

this->GetWorld()->LineTraceSingleByObjectType(OutHit, VFStart_LR, VFLeft,FCollisionObjectQueryParams(FCollisionObjectQueryParams::AllObjects),CollisionParams);
if(OutHit.bBlockingHit){
   UPhysicalMaterial* mat = OutHit.PhysMaterial.Get();
   // Crash here...
   FString str = mat->GetName();
   UE_LOG(LogTemp, Log, TEXT("Hit Mat Name: %s"),*str);
}

The error message is:

CommonLinuxCrashHandler: Signal=11
[2018.05.15-13.37.47:132][110]LogLinux: === Critical error: ===
Unhandled Exception: SIGSEGV: invalid attempt to read memory at address 0x0000000000000000

So I think there is no name for the physMaterial, but there are names

So how can I get the correct material names?

Thanks a lot! :slight_smile:

L

Okay - so I can validate it with:
if(OutHit.PhysMaterial.IsValid())

But then I still do not get these names. How to get them from a FHitResult?

So I can get the name with:
OutHit.GetComponent()->GetMaterial(X)->GetFName().ToString()

but how to get the current X that is hit?