Use braces and handle unexpected enum values
Braces keep later edits inside the intended branch, while the default case gives an unexpected value a defined result.
DamageRules.cppcpp
float GetDamageMultiplier(const EHitZone HitZone)
{
switch (HitZone)
{
case EHitZone::Head:
return 2.0f;
case EHitZone::Torso:
return 1.0f;
case EHitZone::Arm:
case EHitZone::Leg:
return 0.75f;
default:
ensureMsgf(false, TEXT("Unhandled hit zone: %d"), static_cast<int32>(HitZone));
return 1.0f;
}
}- Why
- Adding another line cannot silently move it outside an unbraced branch. An invalid enum value also produces a diagnostic before the function returns its safe fallback.
- Costs
- A default case can hide a newly added enumerator from compiler exhaustiveness warnings. Use
checkNoEntrywhen every enumerator must be handled and no fallback is safe. - Instead
- Use a lookup table when the result is data rather than behavior. Polymorphism fits when each mode owns enough logic to justify its own type.

