UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
PerPlatformPropertiesImpl.inl
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3/*=============================================================================
4 * PerPlatformPropertiesImpl.inl: Serializer implementation
5 *
6 * This file needs to be included by a cpp once for each module that declares a PerPlatformProperty
7 * And following the include, template instantiations of the serializaers for each property class, for example:
8 *
9 * template SLATECORE_API FArchive& operator<<(FArchive&, TPerPlatformProperty<FPerPlatformMyEnumType, EMyEnumType, NAME_EnumProperty>&);
10 * template SLATECORE_API void operator<<(FStructuredArchive::FSlot Slot, TPerPlatformProperty<FPerPlatformMyEnumType, EMyEnumType, NAME_EnumProperty>&);
11 * =============================================================================*/
12
13#pragma once
14
15#if WITH_EDITOR
16#include "Interfaces/ITargetPlatform.h"
17#endif
18
20template<typename StructType, typename ValueType, EName BasePropertyName>
22{
23 bool bCooked = false;
24#if WITH_EDITOR
25 // we don't want to lose this EditorOnly property when saving an Optional object (which normally would be stripped out when cooking)
26 if (Ar.IsCooking() && !Ar.IsSavingOptionalObject())
27 {
28 bCooked = true;
29 Ar << bCooked;
30 // Save out platform override if it exists and Default otherwise
31 ValueType Value = Property.GetValueForPlatform(*Ar.CookingTarget()->IniPlatformName());
32 Ar << Value;
33 }
34 else
35#endif
36 {
37 StructType* This = StaticCast<StructType*>(&Property);
38 Ar << bCooked;
39 Ar << This->Default;
40#if WITH_EDITORONLY_DATA
41 if (!bCooked)
42 {
43 using MapType = decltype(This->PerPlatform);
45 KeyFuncs::SerializePerPlatformMap(Ar, This->PerPlatform);
46 }
47#endif
48 }
49 return Ar;
50}
51
53template<typename StructType, typename ValueType, EName BasePropertyName>
55{
56 FArchive& UnderlyingArchive = Slot.GetUnderlyingArchive();
58
59 bool bCooked = false;
60#if WITH_EDITOR
61 if (UnderlyingArchive.IsCooking())
62 {
63 bCooked = true;
64 Record << SA_VALUE(TEXT("bCooked"), bCooked);
65 // Save out platform override if it exists and Default otherwise
66 ValueType Value = Property.GetValueForPlatform(*UnderlyingArchive.CookingTarget()->IniPlatformName());
67 Record << SA_VALUE(TEXT("Value"), Value);
68 }
69 else
70#endif
71 {
72 StructType* This = StaticCast<StructType*>(&Property);
73 Record << SA_VALUE(TEXT("bCooked"), bCooked);
74 Record << SA_VALUE(TEXT("Value"), This->Default);
75#if WITH_EDITORONLY_DATA
76 if (!bCooked)
77 {
78 using MapType = decltype(This->PerPlatform);
80 KeyFuncs::SerializePerPlatformMap(UnderlyingArchive, Record, This->PerPlatform);
81 }
82#endif
83 }
84}
85
#define TEXT(x)
Definition Platform.h:1272
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
FArchive & operator<<(FArchive &Ar, TPerPlatformProperty< StructType, ValueType, BasePropertyName > &Property)
Definition PerPlatformPropertiesImpl.inl:21
#define SA_VALUE(Name, Value)
Definition StructuredArchiveNameHelpers.h:77
Definition Archive.h:1208
UE_FORCEINLINE_HINT bool IsCooking() const
Definition Archive.h:641
UE_FORCEINLINE_HINT const ITargetPlatform * CookingTarget() const
Definition Archive.h:699
bool IsSavingOptionalObject() const
Definition Archive.h:600
Definition StructuredArchiveSlots.h:144
Definition StructuredArchiveSlots.h:52
UE_API FStructuredArchiveRecord EnterRecord()
Definition StructuredArchiveSlots.h:252
CORE_API FArchive & GetUnderlyingArchive() const
Definition StructuredArchiveSlots.cpp:7
Definition PerPlatformProperties.h:31
Definition PerPlatformProperties.h:116