1. Home
  2. UE5 Compilation Errors
  3. UE5 C++ Compilation Error...
  4. C4996: ‘Function’ Declared Deprecated – UE5 Warning

C4996: ‘Function’ Declared Deprecated – UE5 Warning

Why You’re Seeing This Warning

C4996 is a deprecation warning — the function or API you’re calling still exists, but it’s marked as unsafe, outdated, or being removed in future versions.

Unreal Engine uses this to help devs migrate away from legacy APIs.

You’ll often see this when:

  • Using old C++ standard library functions (like strcpy, sprintf, localtime)
  • Calling UE4-era functions deprecated in UE5 (like GetActorEyesViewPoint() in some contexts)
  • Working with engine features like Sockets, Audio, or Animation that have newer interfaces
  • Using macros or functions tagged with UE_DEPRECATED

💥 Example Warning Message

warning C4996: 'GetWorldSettings': was declared deprecated

Or from standard C++:

warning C4996: 'localtime': This function or variable may be unsafe. Consider using localtime_s instead.

🛠️ Example Code

tm* TimeInfo = localtime(&Now); // ⚠️ C4996: marked unsafe

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


✔️ 1. Use the Recommended Replacement Function

Most C4996 warnings include a note suggesting a safer replacement.

Fix:

tm TimeInfoStruct;
localtime_s(&TimeInfoStruct, &Now); // ✅ Safe version

✔️ 2. Check UE5 Docs or Header Comments for Deprecated Engine Functions

UE5 often wraps deprecated functions with UE_DEPRECATED(...) and suggests what to use instead. Hover over the function or go to definition to see it.

Fix:

// Deprecated:
FVector ViewLoc;
FRotator ViewRot;
GetActorEyesViewPoint(ViewLoc, ViewRot); // ⚠️ May show C4996

// Recommended (example fix):
FVector ViewLoc;
FRotator ViewRot;
Controller->GetPlayerViewPoint(ViewLoc, ViewRot); // ✅

✔️ 3. Silence the Warning (Not Recommended)

If you absolutely must keep using it (e.g. legacy support), you can suppress the warning locally:

#pragma warning(push)
#pragma warning(disable: 4996)

// Your legacy call here
localtime(...);

#pragma warning(pop)

⚠️ Use this only if you know what you’re doing.


✔️ 4. If It’s Your Own Deprecated Code, Use UE_DEPRECATED Properly

If you’re marking your own functions as deprecated:

UE_DEPRECATED(5.0, "Use NewMethod() instead.")
void OldMethod();

That will show a C4996 warning with your custom message — super useful when maintaining APIs in UE5 modules or plugins.


✅ Summary: How to Fix C4996 in UE5

CauseFix Example
Using deprecated functionReplace with modern or safe alternative
UE5 engine method marked unsafeHover and read suggested replacement
Legacy standard library useUse _s or _safe versions like strcpy_s, localtime_s
Writing deprecated APIs yourselfUse UE_DEPRECATED() to warn other devs
Suppressing warning temporarilyUse #pragma warning(disable: 4996) cautiously
Was this article helpful to you? Yes No

How can we help?