# How to fix Unreal Engine from crashing because switch statement is returning NULL?

**URL:** <https://forums.unrealengine.com/t/how-to-fix-unreal-engine-from-crashing-because-switch-statement-is-returning-null/596682>\
**Category:** C++\
**Tags:** Raycast, unreal-engine, UE4, question\
**Created:** [July 4, 2022, 9:44am UTC](https://forums.unrealengine.com/t/how-to-fix-unreal-engine-from-crashing-because-switch-statement-is-returning-null/596682 "2022-07-04T09:44:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ShadowSprite123](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ShadowSprite123](https://forums.unrealengine.com/u/ShadowSprite123)\
**Post date:** [July 4, 2022, 9:44am UTC](https://forums.unrealengine.com/t/how-to-fix-unreal-engine-from-crashing-because-switch-statement-is-returning-null/596682/1 "2022-07-04T09:44:43Z")

</div>

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**

```auto
//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.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_4aa5607e1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_4aa5607e1](https://forums.unrealengine.com/u/anonymous_user_4aa5607e1)\
**Post date:** [July 6, 2022, 10:58am UTC](https://forums.unrealengine.com/t/how-to-fix-unreal-engine-from-crashing-because-switch-statement-is-returning-null/596682/2 "2022-07-06T10:58:29Z")

</div>

I’d just breakpoint on that line and see what `Hit` contains, you might get some clues.
