Getting Surface Type in c++

I am trying to get the surface material from a linetrace in c++, but have been having issues as of yet. The code I’m using is below - basically, I’m trying to convert the byte to an int so I can print the int (also need the int further down the line in my code) but uppon the linetrace hitting something, the engine crashes. I’ve made sure to apply a physical material with a surface type to the surface that the line trace is colliding with. Any help is much appreciated

void ABulletBase::PlayImpactVFX(FHitResult inHit)

int surfaceInt = UKismetMathLibrary::Conv_ByteToInt(inHit.PhysMaterial->SurfaceType);
FString IntString = FString::FromInt(surfaceInt);
if (GEngine)
	GEngine->AddOnScreenDebugMessage(-1, 1.f, FColor::Red, IntString);


PhysMaterial is a pointer, so it might be NULL (or invalid). Try:


prior to first line.

Also, if you run the program in a debugger it will stop the program on the line that caused the crash.