1. Home
  2. UE5 Compilation Errors
  3. UE5 C++ Compilation Error...
  4. C2662: Cannot Convert ‘this’ Pointer from ‘const Type’ to ‘Type &’

C2662: Cannot Convert ‘this’ Pointer from ‘const Type’ to ‘Type &’

What It Means & How to Fix It


🧠 Why You’re Seeing This Error

C2662 means you’re calling a non-const method on a const object, and the compiler won’t allow it. C++ protects const objects from being modified, and UE5 (being C++) follows this rule strictly.

In UE5, this often happens when:

  • You call a non-const method inside a const function
  • You try to use Blueprint-accessible getters/setters on const references
  • You mark a function const in the header but not in the source

💥 Example Error Message

error C2662: 'FString AMyActor::GetName()': cannot convert 'this' pointer from 'const AMyActor' to 'AMyActor &'

🛠️ Example Code

FString AMyActor::GetDescription() const
{
return GetName(); // ❌ C2662: GetName is not marked const
}

✅ How to Fix C2662 in UE5 – Step-by-Step


✔️ 1. Mark the Called Method as const

If GetName() doesn’t change the object’s state, mark it const.

Fix:

FString GetName() const; // In header
FString AMyActor::GetName() const { return Name; } // In cpp

✔️ 2. Don’t Call Non-Const Methods from Const Functions

If the method modifies the object, either:

  • Don’t call it from a const context, or
  • Remove const from the calling function (if appropriate)

✔️ 3. Const-Correctness Is Mandatory in UE5

UE5 requires clean and consistent const usage across declarations and definitions — mismatches will lead to errors like C2662 or C2556.


✅ Summary: How to Fix C2662 in UE5

CauseFix Example
Calling non-const method from constMark method const or remove const from caller
Header/cpp method mismatchAdd const in both header and source
Blueprint method missing constAdd const to BlueprintCallable getters where needed
Was this article helpful to you? Yes No

How can we help?