How can i get surface type? Phys material always null

Super::Notify(MeshComp, Animation, EventReference);

if (!MeshComp || !MeshComp->GetOwner()) return;

AActor* owner = MeshComp->GetOwner();
FVector footLocation = owner->GetActorLocation();
UWorld* world = owner->GetWorld();

if (world == nullptr) return;

FHitResult hitResult;
FVector start = footLocation;
FVector upVector = owner->GetActorUpVector();
FVector end = start + (upVector * -200.0f); 

if (world->LineTraceSingleByChannel(hitResult, start, end, ECC_Visibility))
{
	UPhysicalMaterial* physMaterial = hitResult.PhysMaterial.Get();
	EPhysicalSurface surfaceType = SurfaceType_Default; 

	if (physMaterial)
	{
		surfaceType = UPhysicalMaterial::DetermineSurfaceType(physMaterial);
	}
	PlayFootstepSound(world, footLocation, surfaceType);
}

my code is like this. I want to get the surface but it is always returning NULL. and my surface has set phys materials. I need help figuring this out

1 Like

Double check if it is null in blueprints, then at least you know it is your code or material setup.

2 Likes

I did also do this on blueprints. Same output phys material and surface type returns null

1 Like

check what you’re actually hitting, could be the wrong collision

1 Like

I checked that it was actually hitting the correct mesh but physMaterial was nullptr. However i managed to get what i want with changing how i get material itself.
This is how i managet to do it:
UPrimitiveComponent* hitComponent = hitResult.Component.Get();
UPhysicalMaterial* physMaterial = hitComponent->BodyInstance.GetSimplePhysicalMaterial();

1 Like