17#define UE_USE_CAST_FLAGS (USTRUCT_FAST_ISCHILDOF_IMPL != USTRUCT_ISCHILDOF_STRUCTARRAY)
19#ifndef UE_ENABLE_UNRELATED_CAST_WARNINGS
20#define UE_ENABLE_UNRELATED_CAST_WARNINGS 1
30class UPrimitiveComponent;
32class USkeletalMeshComponent;
34class UStaticMeshComponent;
50template <
typename T,
bool bIsAUObject_IMPL = std::is_convertible_v<T*, const volatile UObject*>>
70 return T::UClassType::StaticClass()->GetName();
74 return T::StaticClass()->GetName();
80 template <
typename Type>
83 template <
typename Type>
87template <
typename Type>
94template <
typename To,
typename From>
97 static_assert(
sizeof(From) > 0 &&
sizeof(To) > 0,
"Attempting to cast between incomplete types");
103 if (
UObject* Obj = Src->_getUObject())
107 return (To*)Obj->GetInterfaceAddress(To::UClassType::StaticClass());
111 if constexpr (std::is_same_v<To, UObject>)
127 static_assert(std::is_base_of_v<UObjectBase, From>,
"Attempting to use Cast<> on a type that is not a UObject or an Interface");
131 if constexpr (std::is_base_of_v<To, From>)
137#if UE_ENABLE_UNRELATED_CAST_WARNINGS
138 UE_STATIC_ASSERT_WARN((std::is_base_of_v<From, To>),
"Attempting to use Cast<> on types that are not related");
140 if (((
const UObject*)Src)->GetClass()->HasAnyCastFlag(UE::CoreUObject::Private::TCastFlags_V<To>))
152 else if constexpr (std::is_base_of_v<To, From>)
158#if UE_ENABLE_UNRELATED_CAST_WARNINGS
159 UE_STATIC_ASSERT_WARN((std::is_base_of_v<From, To>),
"Attempting to use Cast<> on types that are not related");
173template <
typename To,
typename From>
176 return Src && (Src->GetClass() == To::StaticClass()) ? (To*)Src :
nullptr;
182 template <
typename T>
186 if constexpr (std::is_base_of_v<FField, T>)
190 else if constexpr (std::is_base_of_v<UObject, T>)
200 template <
typename To,
typename From>
205 static_assert(
sizeof(From) > 0 &&
sizeof(To) > 0,
"Attempting to cast between incomplete types");
221 template <
typename To,
typename From>
224 static_assert(
sizeof(From) > 0 &&
sizeof(To) > 0,
"Attempting to cast between incomplete types");
247 template <
typename To,
typename From>
252 static_assert(
sizeof(From) > 0 &&
sizeof(To) > 0,
"Attempting to cast between incomplete types");
256 UObject* Obj = Src->_getUObject();
268 static_assert(std::is_base_of_v<UObjectBase, From>,
"Attempting to use Cast<> on a type that is not a UObject or an Interface");
281 template <
typename To,
typename From>
290template <
typename To,
typename From>
295template <
typename To,
typename From>
300template <
typename To,
typename From>
305template <
typename To,
typename From>
312template <
typename To,
typename From>
315 static_assert(
sizeof(To) > 0 &&
sizeof(From) > 0,
"Attempting to cast between incomplete types");
323 if constexpr (std::is_base_of_v<To, From>)
325 return (To*)Src.
Get();
329 #if UE_ENABLE_UNRELATED_CAST_WARNINGS
330 UE_STATIC_ASSERT_WARN((std::is_base_of_v<From, To>),
"Attempting to use Cast<> on types that are not related");
334 return (To*)Src.
Get();
348 else if constexpr (std::is_base_of_v<To, From>)
352 return (To*)Src.
Get();
357#if UE_ENABLE_UNRELATED_CAST_WARNINGS
358 UE_STATIC_ASSERT_WARN((std::is_base_of_v<From, To>),
"Attempting to use Cast<> on types that are not related");
360 if (Src && Src.
IsA<To>())
362 return (To*)Src.
Get();
369template <
typename To,
typename From>
372 static_assert(
sizeof(To) > 0,
"Attempting to cast to an incomplete type");
375 if (
SrcObj && (
SrcObj->GetClass() == To::StaticClass()))
383template <
typename To,
typename From>
386 static_assert(
sizeof(From) > 0 &&
sizeof(To) > 0,
"Attempting to cast between incomplete types");
415 return (To*)((
const FObjectPtr&)Src).Get()->GetInterfaceAddress(To::UClassType::StaticClass());
425template <
typename To,
typename From>
430template <
typename To,
typename From>
435template <
typename To,
typename From>
442#if UE_ENABLE_NOTNULL_WRAPPER
443 template <
typename T,
typename U>
448 template <
typename T,
typename U>
453 template <
typename T,
typename U>
458 template <
typename T,
typename U>
465#define DECLARE_CAST_BY_FLAG(ClassName) \
468 constexpr inline EClassCastFlags UE::CoreUObject::Private::TCastFlags_V<ClassName> = CASTCLASS_##ClassName;
529#undef DECLARE_CAST_BY_FLAG
533 template <
typename T>
540 template <
typename To,
typename From>
547 return dynamic_cast<To
>(Arg);
554 if constexpr (std::is_void_v<ToValueType>)
566 template <
typename To,
typename From>
575 return dynamic_cast<To
>(Arg);
584 static_assert(std::is_lvalue_reference_v<From> || std::is_rvalue_reference_v<To>,
"Cannot dynamic_cast from an rvalue to a non-rvalue reference");
591#define dynamic_cast UE::CoreUObject::Private::DynamicCast
FString GetTypeName()
Definition Casts.h:66
FUNCTION_NON_NULL_RETURN_START TCopyQualifiersFromTo_T< From, To > * CastChecked(From *Src) FUNCTION_NON_NULL_RETURN_END
Definition Casts.h:249
#define UE_USE_CAST_FLAGS
Definition Casts.h:17
TCopyQualifiersFromTo_T< From, To > * Cast(From *Src)
Definition Casts.h:95
COREUOBJECT_API void CastLogError(const TCHAR *FromType, const TCHAR *ToType)
Definition Casts.cpp:8
UE_FORCEINLINE_HINT TCopyQualifiersFromTo_T< From, To > * ExactCast(From *Src)
Definition Casts.h:174
#define DECLARE_CAST_BY_FLAG(ClassName)
Definition Casts.h:465
typename TCopyQualifiersFromTo< From, To >::Type TCopyQualifiersFromTo_T
Definition CopyQualifiersFromTo.h:17
#define UE_STATIC_ASSERT_WARN(bExpression, Message)
Definition CoreMiscDefines.h:431
#define UE_DEPRECATED(Version, Message)
Definition CoreMiscDefines.h:302
FString GetFullNameSafe(const FField *InField)
Definition Field.cpp:1138
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
T TNotNull
Definition NotNull.h:307
EClassCastFlags
Definition ObjectMacros.h:333
@ CASTCLASS_None
Definition ObjectMacros.h:334
@ CLASS_Interface
Definition ObjectMacros.h:234
Definition PlayerController.h:261
Definition UnrealType.h:3702
Definition UnrealType.h:2543
Definition UnrealType.h:2167
Definition UnrealType.h:3411
Definition UnrealType.h:6397
Definition UnrealType.h:2503
Definition EnumProperty.h:29
Definition UnrealType.h:2465
Definition UnrealType.h:2271
Definition UnrealType.h:2336
Definition UnrealType.h:2239
Definition UnrealType.h:2304
Definition UnrealType.h:3561
Definition UnrealType.h:3269
Definition UnrealType.h:3843
Definition UnrealType.h:6464
Definition UnrealType.h:6593
Definition UnrealType.h:6643
Definition UnrealType.h:3649
Definition UnrealType.h:1766
Definition UnrealType.h:2725
Definition UnrealType.h:3087
Definition PropertyOptional.h:185
Definition UnrealType.h:174
Definition UnrealType.h:4028
Definition UnrealType.h:3488
Definition UnrealType.h:3331
Definition UnrealType.h:6306
Definition TextProperty.h:21
Definition UnrealType.h:2368
Definition UnrealType.h:2400
Definition UnrealType.h:2432
Definition UnrealType.h:3204
Definition SubclassOf.h:30
Definition Blueprint.h:403
UE_FORCEINLINE_HINT bool HasAnyCastFlag(EClassCastFlags FlagToCheck) const
Definition Class.h:4546
COREUOBJECT_API void * GetInterfaceAddress(UClass *InterfaceClass)
Definition UObjectBaseUtility.cpp:466
Definition SkinnedMeshComponent.h:258
Type
Definition Object.h:60
@ NullChecked
Definition Object.h:64
Definition CoreGlobals.cpp:268
UObject * ResolveObjectHandleNoRead(FObjectHandle &Handle)
Definition ObjectHandle.h:502
constexpr EClassCastFlags TCastFlags_V
Definition Casts.h:81
constexpr EClassCastFlags TCastFlags_V< const Type >
Definition Casts.h:84
To DynamicCast(From *Arg)
Definition Casts.h:541
void OnHandleRead(const UObject *Object)
Definition ObjectHandleTracking.h:131
UE_STRING_CLASS Result(Forward< LhsType >(Lhs), RhsLen)
Definition String.cpp.inl:732
@ false
Definition radaudio_common.h:23
Definition ObjectPtr.h:55
FORCEINLINE UObject * Get() const
Definition ObjectPtr.h:104
FORCEINLINE FObjectHandle & GetHandleRef() const
Definition ObjectPtr.h:272
COREUOBJECT_API bool IsA(const UClass *SomeBase) const
Definition ObjectPtr.cpp:252
FORCEINLINE UClass * GetClass() const
Definition ObjectPtr.h:109
static char(& Resolve(typename U::UClassType *))[(U::UClassType::StaticClassFlags &CLASS_Interface) ? 2 :1]
static char(& Resolve(...))[1]
@ Value
Definition Casts.h:53
Definition ObjectPtr.h:488
FORCEINLINE T * Get() const
Definition ObjectPtr.h:664
Definition WeakObjectPtrTemplates.h:25
FORCEINLINE T * Get(bool bEvenIfPendingKill) const
Definition WeakObjectPtrTemplates.h:132
@ Value
Definition Casts.h:537