I’ve been trying to do a raycast and seeing what PhysMaterial it hits and doing damage based on the PhysicalMaterial hit on a player but every time I hit the player Unreal Engine crashes as the SurfaceType is returning NULL for some reason.(The PhysMaterial is a custom one)
Player.CPP
//Health is the UHealthComponent and HP is the health value of the component on the player
//Target is the player hit reference and Hit is the FHitResult hit info
switch (Hit.PhysMaterial.Get()->SurfaceType)
{
case SurfaceType1:
UGameplayStatics::ApplyPointDamage(Target, 50.0f, Hit.TraceStart, Hit, GetInstigatorController(), this, UDamageType::StaticClass());
GEngine->AddOnScreenDebugMessage(-1, 1.0f, FColor::Green, FString::SanitizeFloat(Target->Health->HP));
break;
case SurfaceType2:
UGameplayStatics::ApplyPointDamage(Target, 25.0f, Hit.TraceStart, Hit, GetInstigatorController(), this, UDamageType::StaticClass());
GEngine->AddOnScreenDebugMessage(-1, 1.0f, FColor::Green, FString::SanitizeFloat(Target->Health->HP));
break;
case SurfaceType_Default:
UGameplayStatics::ApplyPointDamage(Target, 10.0f, Hit.TraceStart, Hit, GetInstigatorController(), this, UDamageType::StaticClass());
GEngine->AddOnScreenDebugMessage(-1, 1.0f, FColor::Green, FString::SanitizeFloat(Target->Health->HP));
break;
default:
UGameplayStatics::ApplyPointDamage(Target, 10.0f, Hit.TraceStart, Hit, GetInstigatorController(), this, UDamageType::StaticClass());
GEngine->AddOnScreenDebugMessage(-1, 1.0f, FColor::Green, FString::SanitizeFloat(Target->Health->HP));
}
Thanks in advance.