UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
CoreMiscDefines.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "HAL/Platform.h"
7
8// When passed to pragma message will result in clickable warning in VS
9#define WARNING_LOCATION(Line) __FILE__ "(" PREPROCESSOR_TO_STRING(Line) ")"
10
11// This file is included in some resource files, which issue a warning:
12//
13// warning RC4011: identifier truncated to 'PLATFORM_CAN_SUPPORT_EDITORONLY'
14//
15// due to limitations of resource compiler. The only thing needed from this file
16// for resource compilation is PREPROCESSOR_TO_STRING macro at the end, so we take
17// rest of code out for resource compilation.
18#ifndef RC_INVOKED
19
20#define PLAYWORLD_PACKAGE_PREFIX TEXT("UEDPIE")
21
22#ifndef WITH_EDITORONLY_DATA
23 #if !PLATFORM_CAN_SUPPORT_EDITORONLY_DATA || UE_SERVER || PLATFORM_IOS
24 #define WITH_EDITORONLY_DATA 0
25 #else
26 #define WITH_EDITORONLY_DATA 1
27 #endif
28#endif
29
31#ifndef WITH_METADATA
32#define WITH_METADATA WITH_EDITORONLY_DATA
33#elif WITH_EDITORONLY_DATA && !WITH_METADATA
34#error WITH_EDITORONLY_DATA=1 requires WITH_METADATA=1
35#endif
36
37// Option to check for UE_DISABLE_OPTIMIZATION being submitted
38#ifndef UE_CHECK_DISABLE_OPTIMIZATION
39#define UE_CHECK_DISABLE_OPTIMIZATION 0
40#endif
41
42// Set up optimization control macros, now that we have both the build settings and the platform macros
43
44// Defines for submitting optimizations off
45#define UE_DISABLE_OPTIMIZATION_SHIP PRAGMA_DISABLE_OPTIMIZATION_ACTUAL
46
47//in debug keep optimizations off for the enable macro otherwise code following enable will be optimized
48#if UE_BUILD_DEBUG
49 #define UE_ENABLE_OPTIMIZATION_SHIP PRAGMA_DISABLE_OPTIMIZATION_ACTUAL
50#else
51 #define UE_ENABLE_OPTIMIZATION_SHIP PRAGMA_ENABLE_OPTIMIZATION_ACTUAL
52#endif
53
54// if running on a build machine assert on the dev optimizations macros to validate that code is not being submitted with optimizations off
55#if UE_CHECK_DISABLE_OPTIMIZATION
56 #define UE_DISABLE_OPTIMIZATION static_assert(false, "Error UE_DISABLE_OPTIMIZATION submitted. Use UE_DISABLE_OPTIMIZATION_SHIP to submit with optimizations off.");
57 #define UE_ENABLE_OPTIMIZATION static_assert(false, "Error UE_ENABLE_OPTIMIZATION submitted. Use UE_ENABLE_OPTIMIZATION_SHIP to submit with optimizations off.");
58#else
59 #define UE_DISABLE_OPTIMIZATION UE_DISABLE_OPTIMIZATION_SHIP
60 #define UE_ENABLE_OPTIMIZATION UE_ENABLE_OPTIMIZATION_SHIP
61#endif
62
63#define PRAGMA_DISABLE_OPTIMIZATION \
64 UE_DEPRECATED_MACRO(5.2, "PRAGMA_DISABLE_OPTIMIZATION has been deprecated. Use UE_DISABLE_OPTIMIZATION for temporary development or UE_DISABLE_OPTIMIZATION_SHIP to submit") \
65 UE_DISABLE_OPTIMIZATION_SHIP
66
67#define PRAGMA_ENABLE_OPTIMIZATION \
68 UE_DEPRECATED_MACRO(5.2, "PRAGMA_ENABLE_OPTIMIZATION has been deprecated. Use UE_ENABLE_OPTIMIZATION for temporary development or UE_ENABLE_OPTIMIZATION_SHIP to submit") \
69 UE_ENABLE_OPTIMIZATION_SHIP
70
71#if UE_BUILD_DEBUG
72 #define FORCEINLINE_DEBUGGABLE FORCEINLINE_DEBUGGABLE_ACTUAL
73#else
74 #define FORCEINLINE_DEBUGGABLE FORCEINLINE
75#endif
76
77// Macro to disable inlining of function calls within the statement that follows
78// e.g: UE_DONT_INLINE_CALL ThisFunctionCallWontBeInlined(Foo->ThisIsntInlinedEither());
79#if !defined(UE_DONT_INLINE_CALL)
80 #if defined(__clang__) && defined(__has_cpp_attribute) && __has_cpp_attribute(clang::noinline)
81 #define UE_DONT_INLINE_CALL [[clang::noinline]]
82 #else
83 #define UE_DONT_INLINE_CALL
84 #endif
85#endif
86
87
88#if STATS
89 #define CLOCK_CYCLES(Timer) {Timer -= FPlatformTime::Cycles();}
90 #define UNCLOCK_CYCLES(Timer) {Timer += FPlatformTime::Cycles();}
91#else
92 #define CLOCK_CYCLES(Timer)
93 #define UNCLOCK_CYCLES(Timer)
94#endif
95
96#define SHUTDOWN_IF_EXIT_REQUESTED
97#define RETURN_IF_EXIT_REQUESTED
98#define RETURN_VAL_IF_EXIT_REQUESTED(x)
99
100#if CHECK_PUREVIRTUALS
101#define PURE_VIRTUAL(func,...) =0;
102#else
103#define PURE_VIRTUAL(func,...) { LowLevelFatalError(TEXT("Pure virtual not implemented (%s)"), TEXT(#func)); __VA_ARGS__ }
104#endif
105
106
107// Code analysis features
108#ifndef USING_CODE_ANALYSIS
109 #define USING_CODE_ANALYSIS 0
110#endif
111
112#if USING_CODE_ANALYSIS
113 #if !defined( CA_IN ) || !defined( CA_OUT ) || !defined( CA_READ_ONLY ) || !defined( CA_WRITE_ONLY ) || !defined( CA_VALID_POINTER ) || !defined( CA_CHECK_RETVAL ) || !defined( CA_NO_RETURN ) || !defined( CA_SUPPRESS ) || !defined( CA_ASSUME )
114 #error Code analysis macros are not configured correctly for this platform
115 #endif
116#else
117 // Just to be safe, define all of the code analysis macros to empty macros
118 #define CA_IN
119 #define CA_OUT
120 #define CA_READ_ONLY
121 #define CA_WRITE_ONLY
122 #define CA_VALID_POINTER
123 #define CA_CHECK_RETVAL
124 #define CA_NO_RETURN
125 #define CA_SUPPRESS( WarningNumber )
126 #define CA_ASSUME( Expr ) ((void)sizeof((bool)(Expr)))
127 #define CA_CONSTANT_IF(Condition) if (Condition)
128#endif
129
130#ifndef USING_INSTRUMENTATION
131 #define USING_INSTRUMENTATION 0
132#endif
133
134#ifndef USING_THREAD_SANITISER
135 #define USING_THREAD_SANITISER 0
136#endif
137
138#if USING_THREAD_SANITISER || USING_INSTRUMENTATION
139 #if !defined( TSAN_SAFE ) || !defined( TSAN_BEFORE ) || !defined( TSAN_AFTER ) || !defined( TSAN_ATOMIC )
140 #error Thread Sanitiser macros are not configured correctly for this platform
141 #endif
142#else
143 // Define TSAN macros to empty when not enabled
144 #define TSAN_SAFE
145 #define TSAN_BEFORE(Addr)
146 #define TSAN_AFTER(Addr)
147 #define TSAN_ATOMIC(Type) Type
148#endif
149
150enum {INDEX_NONE = -1 };
151enum {UNICODE_BOM = 0xfeff };
152
159// Used to add an explicitly consteval constructor when the default constructor for a type cannot
160// be made constexpr (e.g. we are attempting to avoid zero-initialization when constructing at runtime)
164
165#endif // RC_INVOKED
166
167// Push and pop macro definitions
168#ifdef __clang__
169 #define UE_PUSH_MACRO(name) _Pragma(PREPROCESSOR_TO_STRING(push_macro(name)))
170 #define UE_POP_MACRO(name) _Pragma(PREPROCESSOR_TO_STRING(pop_macro(name)))
171#else
172 #define UE_PUSH_MACRO(name) __pragma(push_macro(name))
173 #define UE_POP_MACRO(name) __pragma(pop_macro(name))
174#endif
175
176#ifdef __COUNTER__
177 // Created a variable with a unique name
178 #define ANONYMOUS_VARIABLE( Name ) PREPROCESSOR_JOIN(Name, __COUNTER__)
179#else
180 // Created a variable with a unique name.
181 // Less reliable than the __COUNTER__ version.
182 #define ANONYMOUS_VARIABLE( Name ) PREPROCESSOR_JOIN(Name, __LINE__)
183#endif
184
186#define UE_CALL_ONCE(Func, ...) static int32 ANONYMOUS_VARIABLE(ThreadSafeOnce) = ((Func)(__VA_ARGS__), 1)
187
188#if defined (__INTELLISENSE__)
189
190 #define UE_DEPRECATED(Version, Message)
191 #define UE_INTERNAL
192 #define PRAGMA_DISABLE_INTERNAL_WARNINGS
193 #define PRAGMA_ENABLE_INTERNAL_WARNINGS
194 #define UE_EXPERIMENTAL(Version, Message)
195 #define PRAGMA_DISABLE_EXPERIMENTAL_WARNINGS
196 #define PRAGMA_ENABLE_EXPERIMENTAL_WARNINGS
197
198#else // defined (__INTELLISENSE__)
199
302 #define UE_DEPRECATED(Version, Message) [[deprecated(Message " - Please update your code to the new API before upgrading to the next release, otherwise your project will no longer compile.")]]
303
313 #define UE_DEPRECATED_ERROR(Version, Message) [[deprecated(Message " - ** This is a compile error so as to avoid data loss, or similar. ** You will need to update your code to get it to compile correctly.")]]
314
318 #define UE_DEPRECATED_ERROR_WITH_MOVED_MEMBER_MESSAGE(Version, Member, Message) \
319 [[deprecated(Message " ** This is a compile error so as to avoid data loss, or similar. ** You will need to update your code to get it to compile correctly.")]] \
320 FDeprecationCompileError Member;
321
323 #define UE_DEPRECATED_ERROR_WITH_MOVED_MEMBER(Version, Member) UE_DEPRECATED_ERROR_WITH_MOVED_MEMBER_MESSAGE(Version, Member, "The member " #Member " has moved. Use the Get/Set" #Member " accessors instead.")
324
326 #define UE_DEPRECATED_ERROR_WITH_MOVED_BOOL_MEMBER(Version, Member) UE_DEPRECATED_ERROR_WITH_MOVED_MEMBER_MESSAGE(Version, b##Member, "The member b" #Member " has moved. Use the Get/Set" #Member " accessors instead.")
327
340 #if UE_VALIDATE_INTERNAL_API
341 #define UE_INTERNAL [[deprecated("This API is internal to the engine. As such, there is no guarantee that it won't change or be removed in future releases. Please use at your own risk.")]]
342 #define PRAGMA_DISABLE_INTERNAL_WARNINGS PRAGMA_DISABLE_DEPRECATION_WARNINGS
343 #define PRAGMA_ENABLE_INTERNAL_WARNINGS PRAGMA_ENABLE_DEPRECATION_WARNINGS
344 #else // UE_VALIDATE_INTERNAL_API
345 #define UE_INTERNAL
346 #define PRAGMA_DISABLE_INTERNAL_WARNINGS
347 #define PRAGMA_ENABLE_INTERNAL_WARNINGS
348 #endif // !UE_VALIDATE_INTERNAL_API
349
364 #if UE_VALIDATE_EXPERIMENTAL_API
365 #define UE_EXPERIMENTAL(Version, Message) [[deprecated(Message " - This API is experimental. As such, there is no guarantee that it won't change or be removed in future releases. Please use at your own risk.")]]
366 #define PRAGMA_DISABLE_EXPERIMENTAL_WARNINGS PRAGMA_DISABLE_DEPRECATION_WARNINGS
367 #define PRAGMA_ENABLE_EXPERIMENTAL_WARNINGS PRAGMA_ENABLE_DEPRECATION_WARNINGS
368 #else // UE_VALIDATE_EXPERIMENTAL_API
369 #define UE_EXPERIMENTAL(Version, Message)
370 #define PRAGMA_DISABLE_EXPERIMENTAL_WARNINGS
371 #define PRAGMA_ENABLE_EXPERIMENTAL_WARNINGS
372 #endif // !UE_VALIDATE_EXPERIMENTAL_API
373
374#endif // !defined(__INTELLISENSE__)
375
376#ifndef UE_DEPRECATED_FORGAME
377 #define UE_DEPRECATED_FORGAME PREPROCESSOR_NOTHING_FUNCTION
378#endif
379
380#ifndef UE_DEPRECATED_FORENGINE
381 #define UE_DEPRECATED_FORENGINE UE_DEPRECATED
382#endif
383
384
388#if defined(UE_DIRECT_HEADER_COMPILE)
389 // Don't warn about the deprecated header when we are directly compiling the header
390 #define UE_DEPRECATED_HEADER(Version, Message)
391#elif defined(_MSC_VER)
392 #if UE_WARNINGS_AS_ERRORS
393 #define UE_DEPRECATED_HEADER(Version, Message) __pragma(message(__FILE__ "(" PREPROCESSOR_TO_STRING(__LINE__) "): error C4996: " Message " Please update your code to the new API before upgrading to the next release, otherwise your project will no longer compile."))
394 #else
395 #define UE_DEPRECATED_HEADER(Version, Message) __pragma(message(__FILE__ "(" PREPROCESSOR_TO_STRING(__LINE__) "): warning C4996: " Message " Please update your code to the new API before upgrading to the next release, otherwise your project will no longer compile."))
396 #endif
397#else
398 #define UE_DEPRECATED_HEADER(Version, Message) _Pragma(PREPROCESSOR_TO_STRING(message(Message " Please update your code to the new API before upgrading to the next release, otherwise your project will no longer compile.")))
399#endif
400
401
402/*
403 * Macro that can be defined in the target file to strip deprecated properties in objects across the engine that check against this define.
404 * Can be used by project that have migrated away from using deprecated functions and data members to potentially gain back some memory and perf.
405 * @note This is a define that engine developer may use when deprecating properties to allow additional memory savings when a project is compliant with deprecation notice.
406 * It doesn't indicate that all deprecated properties will be stripped.
407 */
408#ifndef UE_STRIP_DEPRECATED_PROPERTIES
409 #define UE_STRIP_DEPRECATED_PROPERTIES 0
410#endif
411
412template <bool bIsDeprecated>
416
420#define UE_STATIC_DEPRECATE(Version, bExpression, Message) \
421 struct PREPROCESSOR_JOIN(FDeprecationMsg_, __LINE__) { \
422 [[deprecated(Message " - Please update your code to the new API before upgrading to the next release, otherwise your project will no longer compile.")]] \
423 static constexpr int condition(TStaticDeprecateExpression<true>) { return 1; } \
424 static constexpr int condition(TStaticDeprecateExpression<false>) { return 1; } \
425 }; \
426 enum class PREPROCESSOR_JOIN(EDeprecationMsg_, __LINE__) { Value = PREPROCESSOR_JOIN(FDeprecationMsg_, __LINE__)::condition(TStaticDeprecateExpression<!!(bExpression)>()) }
427
431#define UE_STATIC_ASSERT_WARN(bExpression, Message) \
432 struct PREPROCESSOR_JOIN(FStaticWarningMsg_, __LINE__) { \
433 [[deprecated(Message)]] \
434 static constexpr int condition(TStaticDeprecateExpression<true>) { return 1; } \
435 static constexpr int condition(TStaticDeprecateExpression<false>) { return 1; } \
436 }; \
437 enum class PREPROCESSOR_JOIN(EStaticWarningMsg_, __LINE__) { Value = PREPROCESSOR_JOIN(FStaticWarningMsg_, __LINE__)::condition(TStaticDeprecateExpression<!(bExpression)>()) }
438
439// These defines are used to mark a difference between two pointers as expected to fit into the specified range
440// while still leaving something searchable if the surrounding code is updated to work with a 64 bit count/range
441// in the future
442#define UE_PTRDIFF_TO_INT32(argument) static_cast<int32>(argument)
443#define UE_PTRDIFF_TO_UINT32(argument) static_cast<uint32>(argument)
444
457#define UE_NONCOPYABLE(TypeName) \
458 TypeName(TypeName&&) = delete; \
459 TypeName(const TypeName&) = delete; \
460 TypeName& operator=(const TypeName&) = delete; \
461 TypeName& operator=(TypeName&&) = delete;
462
463
470{
473 {
474 return InternalId != INDEX_NONE;
475 }
476
479 {
480 return InternalId;
481 }
482
490
492 {
493 return InternalId == Other.InternalId;
494 }
495
497 {
498 return InternalId != Other.InternalId;
499 }
500
502 {
503 return UserId.InternalId;
504 }
505
506 // This should be deprecated when the online code uniformly handles FPlatformUserId */
507 // UE_DEPRECATED(5.x, "Implicit conversion to user index is deprecated, use FPlatformMisc::GetUserIndexForPlatformUser")
508 UE_FORCEINLINE_HINT constexpr operator int32() const { return InternalId; }
509
510private:
512 int32 InternalId = INDEX_NONE;
513};
514
517
524{
532
534 {
535 return InternalId;
536 }
537
540 {
541 return InternalId >= 0;
542 }
543
545 {
546 return InternalId == Other.InternalId;
547 }
548
550 {
551 return InternalId != Other.InternalId;
552 }
553
555 {
556 return InternalId < Other.InternalId;
557 }
558
560 {
561 return InternalId <= Other.InternalId;
562 }
563
565 {
566 return InternalId > Other.InternalId;
567 }
568
570 {
571 return InternalId >= Other.InternalId;
572 }
573
575 {
576 return InputId.InternalId;
577 }
578
579private:
580
586 int32 InternalId = INDEX_NONE;
587};
588
591
594{
596 Invalid,
597
599 Unknown,
600
603
606};
607
617
619#ifndef UE_WITH_REMOTE_OBJECT_HANDLE
620 #define UE_WITH_REMOTE_OBJECT_HANDLE 0
621#endif
EInputDeviceConnectionState
Definition CoreMiscDefines.h:594
ENoInit
Definition CoreMiscDefines.h:158
@ NoInit
Definition CoreMiscDefines.h:158
@ INDEX_NONE
Definition CoreMiscDefines.h:150
EPerElement
Definition CoreMiscDefines.h:163
@ PerElement
Definition CoreMiscDefines.h:163
constexpr FPlatformUserId PLATFORMUSERID_NONE
Definition CoreMiscDefines.h:516
@ UNICODE_BOM
Definition CoreMiscDefines.h:151
constexpr FInputDeviceId INPUTDEVICEID_NONE
Definition CoreMiscDefines.h:590
EForceInit
Definition CoreMiscDefines.h:154
@ ForceInitToZero
Definition CoreMiscDefines.h:156
@ ForceInit
Definition CoreMiscDefines.h:155
EInPlace
Definition CoreMiscDefines.h:162
@ InPlace
Definition CoreMiscDefines.h:162
EConstEval
Definition CoreMiscDefines.h:161
@ ConstEval
Definition CoreMiscDefines.h:161
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
#define UE_FORCEINLINE_HINT
Definition Platform.h:723
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
uint8_t uint8
Definition binka_ue_file_header.h:8
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition CoreMiscDefines.h:312
Definition CoreMiscDefines.h:524
UE_FORCEINLINE_HINT bool operator<(const FInputDeviceId &Other) const
Definition CoreMiscDefines.h:554
UE_FORCEINLINE_HINT bool operator==(const FInputDeviceId &Other) const
Definition CoreMiscDefines.h:544
UE_FORCEINLINE_HINT bool IsValid() const
Definition CoreMiscDefines.h:539
UE_FORCEINLINE_HINT bool operator>(const FInputDeviceId &Other) const
Definition CoreMiscDefines.h:564
UE_FORCEINLINE_HINT bool operator>=(const FInputDeviceId &Other) const
Definition CoreMiscDefines.h:569
UE_FORCEINLINE_HINT int32 GetId() const
Definition CoreMiscDefines.h:533
UE_FORCEINLINE_HINT friend uint32 GetTypeHash(const FInputDeviceId &InputId)
Definition CoreMiscDefines.h:574
UE_FORCEINLINE_HINT bool operator!=(const FInputDeviceId &Other) const
Definition CoreMiscDefines.h:549
UE_FORCEINLINE_HINT bool operator<=(const FInputDeviceId &Other) const
Definition CoreMiscDefines.h:559
static FInputDeviceId CreateFromInternalId(int32 InInternalId)
Definition CoreMiscDefines.h:526
Definition CoreMiscDefines.h:610
FPlatformUserId OwningPlatformUser
Definition CoreMiscDefines.h:612
EInputDeviceConnectionState ConnectionState
Definition CoreMiscDefines.h:615
Definition CoreMiscDefines.h:470
UE_FORCEINLINE_HINT bool operator==(const FPlatformUserId &Other) const
Definition CoreMiscDefines.h:491
UE_FORCEINLINE_HINT bool operator!=(const FPlatformUserId &Other) const
Definition CoreMiscDefines.h:496
UE_FORCEINLINE_HINT bool IsValid() const
Definition CoreMiscDefines.h:472
UE_FORCEINLINE_HINT int32 GetInternalId() const
Definition CoreMiscDefines.h:478
UE_FORCEINLINE_HINT friend uint32 GetTypeHash(const FPlatformUserId &UserId)
Definition CoreMiscDefines.h:501
static FPlatformUserId CreateFromInternalId(int32 InInternalId)
Definition CoreMiscDefines.h:484
Definition CoreMiscDefines.h:414