C2238: Unexpected Token(s) Preceding ‘;’ in Unreal Engine 5 (UE5 C++) – What It Means & How to Fix It
🧠 Why You’re Seeing This Error
The C2238
error means there’s something before a semicolon that doesn’t belong there — often a malformed declaration or stray symbol.
In Unreal Engine 5, this often happens when:
- You forget to fully declare a variable (e.g., missing a type or name)
- You accidentally type extra characters like commas or operators
- You copy-paste Unreal macros or UPROPERTY() lines but forget to complete them
- You have mismatched parentheses, angle brackets, or templates
💥 Example Error Message
error C2238: unexpected token(s) preceding ';'
🛠️ Example Code
UCLASS()
class AMyActor : public AActor
{
GENERATED_BODY()
int32 ; // ❌ C2238: unexpected token(s) preceding ';'
};
✅ How to Fix C2238 UE5 – Step-by-Step
✔️ 1. Make Sure All Variable Declarations Include a Name
Fix:
int32 Health; // ✅ Valid variable declaration
✔️ 2. Avoid Stray Semicolons After Templates or Macros
Wrong:
TArray<>; // ❌ Missing type inside angle brackets
Fix:
TArrayValues; // ✅ Proper declaration
✔️ 3. Check Copy-Pasted UPROPERTY / UFUNCTION Lines
Wrong:
UPROPERTY() int32; // ❌ Missing variable name
Fix:
UPROPERTY() int32 Score; // ✅ Valid property declaration
✔️ 4. Check for Dangling Commas, Parentheses, or Brackets
Sometimes, the problem is not in the line with the error but the line right before it.
Wrong:
int32 Health,
; // ❌ C2238: stray comma before semicolon
Fix:
int32 Health; // ✅
✅ Summary: How to Fix C2238 in UE5
Cause | Solution |
---|---|
Missing variable name | Add name after type (int32 Health; ) |
Broken template | Fill in template params (TArray<int32> ) |
Stray characters before ; | Remove extra commas, operators, etc. |
Copy-paste errors from macros | Complete the line after UPROPERTY , etc. |
Invalid declaration format | Always include both type and name |