1. Home
  2. UE5 Compilation Errors
  3. UE5 C++ Compilation Error...
  4. C2228: Left of ‘.member’ Must Have Class/Struct/Union

C2228: Left of ‘.member’ Must Have Class/Struct/Union

What It Means & How to Fix It


🧠 Why You’re Seeing This Error

The C2228 error means you’re trying to access a member variable or function using the dot . operator, but what’s on the left isn’t a class, struct, or union — at least not in the way the compiler sees it.

In UE5, this almost always happens when:

  • You’re using the dot . operator on a pointer
  • You’re trying to access members from something that isn’t fully initialized or is nullptr
  • You’re chaining functions incorrectly and the return type isn’t what you thought it was

💥 Example Error Message

error C2228: left of '.SetActorLocation' must have class/struct/union

🛠️ Example Code

AActor* MyActor = GetOwner();
MyActor.SetActorLocation(FVector(0.f, 0.f, 0.f)); // ❌ C2228

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


✔️ 1. Use -> When Accessing Members from a Pointer

MyActor is a pointer (AActor*), so you must use -> instead of ..

Fix:

MyActor->SetActorLocation(FVector(0.f, 0.f, 0.f)); // ✅ Correct usage

✔️ 2. Check Return Types of Chained Functions

Maybe you thought a function returned a class instance, but it actually returns a pointer — or vice versa.

Wrong:

GetWorld().GetTimeSeconds(); // ❌ GetWorld() returns a pointer

Fix:

GetWorld()->GetTimeSeconds(); // ✅ Use `->` on pointer return

✔️ 3. Use . Only with Instances (Not Pointers)

Example:

FVector Location;
Location.X = 100.f; // ✅ Using dot with struct (not a pointer)

✔️ 4. Use (*Pointer).Member Only If You Know What You’re Doing

This is the alternative to ->, but not recommended unless you have a specific reason.

(*MyActor).SetActorLocation(...); // ✅ but use -> instead for readability

✅ Summary: How to Fix C2228 in UE5

CauseFix Example
Using . on a pointerUse -> instead (MyActor->SetActorLocation(...))
Misunderstanding return typesCheck if the return value is a pointer or instance
Incorrect member accessAccess with . only if it’s not a pointer
Was this article helpful to you? Yes No

How can we help?