UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
PerPlatformProperties.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3/*=============================================================================
4PerPlatformProperties.h: Property types that can be overridden on a per-platform basis at cook time
5=============================================================================*/
6
7#pragma once
8
9#include "CoreMinimal.h"
10#include "UObject/Object.h"
12#include "Containers/Map.h"
13#include "Algo/Find.h"
16#include "Misc/FrameRate.h"
19
20#include "PerPlatformProperties.generated.h"
21
23{
24 template<typename MapType>
29
30 template<typename NameType>
31 struct FNameFuncs;
32
33 template<>
35 {
36 static FName NameToKey(FName Name) { return Name; }
37
38 template<typename ValueType>
40 {
41 Ar << Map;
42 }
43
44 template<typename ValueType>
46 {
47 Record << SA_VALUE(TEXT("PerPlatform"), Map);
48 }
49 };
50
51 template<>
53 {
55
56 template<typename ValueType>
58 {
59 if( Ar.IsLoading())
60 {
62 Ar << TempMap;
63 Map.Reset();
65 {
66 Map.Add(FMemoryImageName(Pair.Key), Pair.Value);
67 }
68 }
69 else
70 {
73 {
74 TempMap.Add(FName(Pair.Key), Pair.Value);
75 }
76 Ar << TempMap;
77 }
78 }
79
80 template<typename ValueType>
82 {
83 if (UnderlyingArchive.IsLoading())
84 {
86
87 Record << SA_VALUE(TEXT("PerPlatform"), TempMap);
88 Map.Reset();
90 {
91 Map.Add(FMemoryImageName(Pair.Key), Pair.Value);
92 }
93 }
94 else
95 {
98 {
99 TempMap.Add(FName(Pair.Key), Pair.Value);
100 }
101 Record << SA_VALUE(TEXT("PerPlatform"), TempMap);
102 }
103 }
104 };
105
106 template<typename MapType>
108}
109
114template<typename _StructType, typename _ValueType, EName _BasePropertyName>
116{
117 typedef _ValueType ValueType;
119
120#if WITH_EDITOR
122 _ValueType GetValueForPlatform(FName PlatformName) const
123 {
125
126 using MapType = decltype(This->PerPlatform);
127 using KeyFuncs = typename PerPlatformProperty::Private::KeyFuncs<MapType>;
128
129 const _ValueType* Ptr = This->PerPlatform.Find(KeyFuncs::NameToKey(PlatformName));
130
131 if (Ptr == nullptr)
132 {
134 if (Info.PlatformGroupName != NAME_None)
135 {
136 Ptr = This->PerPlatform.Find(KeyFuncs::NameToKey(Info.PlatformGroupName));
137 }
138 }
139
140 return Ptr ? *Ptr : This->Default;
141 }
142#endif
143
144 _ValueType GetDefault() const
145 {
147 return This->Default;
148 }
149
150 _ValueType GetValue() const
151 {
152#if WITH_EDITORONLY_DATA && WITH_EDITOR
153 FName PlatformName;
154 // Lookup the override preview platform info, if any
155 // @todo this doesn't set PlatformName, just a group, but GetValueForPlatform() will technically work being given a Group name instead of a platform name, so we just use it
156 if (UObject::OnGetPreviewPlatform.IsBound() && UObject::OnGetPreviewPlatform.Execute(PlatformName))
157 {
158 return GetValueForPlatform(PlatformName);
159 }
160 else
161#endif
162 {
164 return This->Default;
165 }
166 }
167
168 /* Load old properties that have been converted to FPerPlatformX */
170 {
171 if (Tag.Type == _BasePropertyName)
172 {
174 _ValueType OldValue;
175 Ar << OldValue;
176 *This = _StructType(OldValue);
177 return true;
178 }
179 return false;
180 }
181
182 /* Serialization */
184 {
185 Ar << *this;
186 return true;
187 }
188
189 /* Serialization */
191 {
192 Slot << *this;
193 return true;
194 }
195};
196
197
198template<typename _StructType, typename _ValueType, EName _BasePropertyName>
200template<typename _StructType, typename _ValueType, EName _BasePropertyName>
202
204
206USTRUCT(BlueprintType)
208#if CPP
210#endif
211{
213
214 UPROPERTY(BlueprintReadOnly, EditAnywhere, Category = PerPlatform)
216
217#if WITH_EDITORONLY_DATA
218 UPROPERTY(EditAnywhere, Category = PerPlatform, meta = (AllowedInOptional))
220#endif
221
223 : Default(0)
224 {
225 }
226
231
232 COREUOBJECT_API FString ToString() const;
233
235};
236
237USTRUCT()
269
272{
273#if WITH_EDITORONLY_DATA
274 for (const TPair<FMemoryImageName, int32>& Pair : Other.PerPlatform)
275 {
276 PerPlatform.Add(FName(Pair.Key), Pair.Value);
277 }
278#endif
279}
280
283
284template<>
287{
288 enum
289 {
290 WithSerializeFromMismatchedTag = true,
291 WithSerializer = true
292 };
293 static constexpr EPropertyObjectReferenceType WithSerializerObjectReferences = EPropertyObjectReferenceType::None;
294};
295
297
299USTRUCT(BlueprintType, meta = (CanFlattenStruct))
301#if CPP
303#endif
304{
306
307 UPROPERTY(BlueprintReadOnly, EditAnywhere, Category = PerPlatform)
309
310#if WITH_EDITORONLY_DATA
311 UPROPERTY(EditAnywhere, Category = PerPlatform, meta = (AllowedInOptional))
313#endif
314
316 : Default(0.f)
317 {
318 }
319
324
326};
328
354
357{
358#if WITH_EDITORONLY_DATA
359 for (const TPair<FMemoryImageName, float>& Pair : Other.PerPlatform)
360 {
361 PerPlatform.Add(FName(Pair.Key), Pair.Value);
362 }
363#endif
364}
365
366template<>
369{
370 enum
371 {
372 WithSerializeFromMismatchedTag = true,
373 WithSerializer = true
374 };
375 static constexpr EPropertyObjectReferenceType WithSerializerObjectReferences = EPropertyObjectReferenceType::None;
376};
377
379USTRUCT()
381#if CPP
383#endif
384{
386
387 UPROPERTY(EditAnywhere, Category = PerPlatform)
389
390#if WITH_EDITORONLY_DATA
391 UPROPERTY(EditAnywhere, Category = PerPlatform, meta = (AllowedInOptional))
393#endif
394
396 : Default(false)
397 {
398 }
399
404};
406
407template<>
410{
411 enum
412 {
413 WithSerializeFromMismatchedTag = true,
414 WithSerializer = true
415 };
416 static constexpr EPropertyObjectReferenceType WithSerializerObjectReferences = EPropertyObjectReferenceType::None;
417};
418
420USTRUCT(BlueprintType)
422#if CPP
424#endif
425{
427
428 UPROPERTY(EditAnywhere, Category = PerPlatform)
430
431#if WITH_EDITORONLY_DATA
432 UPROPERTY(EditAnywhere, Category = PerPlatform, meta = (AllowedInOptional))
434#endif
435
437 : Default(30, 1)
438 {
439 }
440
445
447 {
448 if(const UStruct* FrameRateStruct = FindObject<UStruct>(FTopLevelAssetPath("/Script/CoreUObject.FrameRate")))
449 {
451 Ar << Value.Denominator;
452 Ar << Value.Numerator;
453 Default = Value;
454
455 return true;
456 }
457
458 return false;
459 }
460};
461
463
464template<>
467{
468 enum
469 {
470 WithSerializeFromMismatchedTag = false,
471 WithSerializer = true
472 };
473 static constexpr EPropertyObjectReferenceType WithSerializerObjectReferences = EPropertyObjectReferenceType::None;
474};
FArchive & operator<<(FArchive &Ar, TPerPlatformProperty< _StructType, _ValueType, _BasePropertyName > &P)
#define TEXT(x)
Definition Platform.h:1272
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
#define LAYOUT_FIELD(T, Name,...)
Definition MemoryLayout.h:471
#define LAYOUT_FIELD_EDITORONLY(T, Name,...)
Definition MemoryLayout.h:488
const bool
Definition NetworkReplayStreaming.h:178
#define UPROPERTY(...)
UObject definition macros.
Definition ObjectMacros.h:744
#define USTRUCT(...)
Definition ObjectMacros.h:746
EPropertyObjectReferenceType
Definition ObjectMacros.h:533
#define GENERATED_USTRUCT_BODY(...)
Definition ObjectMacros.h:767
USkinnedMeshComponent float
Definition SkinnedMeshComponent.h:60
#define SA_VALUE(Name, Value)
Definition StructuredArchiveNameHelpers.h:77
Definition Archive.h:1208
UE_FORCEINLINE_HINT bool IsLoading() const
Definition Archive.h:236
virtual CORE_API void Reset()
Definition Archive.cpp:151
Definition NameTypes.h:617
Definition StructuredArchiveSlots.h:144
Definition StructuredArchiveSlots.h:52
Definition UnrealString.h.inl:34
Definition Class.h:480
Definition PerPlatformProperties.h:23
@ false
Definition radaudio_common.h:23
static CORE_API const FDataDrivenPlatformInfo & GetPlatformInfo(const FString &PlatformName)
Definition DataDrivenPlatformInfoRegistry.cpp:598
Definition DataDrivenPlatformInfoRegistry.h:120
Definition FrameRate.h:21
Definition PerPlatformProperties.h:333
FFreezablePerPlatformFloat()
Definition PerPlatformProperties.h:341
FFreezablePerPlatformFloat(float InDefaultValue)
Definition PerPlatformProperties.h:342
DECLARE_TYPE_LAYOUT(FFreezablePerPlatformFloat, NonVirtual)
LAYOUT_FIELD(float, Default)
FFreezablePerPlatformFloat(const FPerPlatformFloat &Other)
Definition PerPlatformProperties.h:343
LAYOUT_FIELD_EDITORONLY(FPerPlatformMap, PerPlatform)
Definition PerPlatformProperties.h:242
FFreezablePerPlatformInt(const FPerPlatformInt &Other)
Definition PerPlatformProperties.h:256
FFreezablePerPlatformInt(int32 InDefaultValue)
Definition PerPlatformProperties.h:255
COREUOBJECT_API FString ToString() const
Definition PerPlatformProperties.cpp:45
DECLARE_TYPE_LAYOUT(FFreezablePerPlatformInt, NonVirtual)
Definition NameTypes.h:558
Definition PerPlatformProperties.h:384
FPerPlatformBool()
Definition PerPlatformProperties.h:395
FPerPlatformBool(bool InDefaultValue)
Definition PerPlatformProperties.h:400
Definition PerPlatformProperties.h:304
FPerPlatformFloat()
Definition PerPlatformProperties.h:315
FPerPlatformFloat(float InDefaultValue)
Definition PerPlatformProperties.h:320
Definition PerPlatformProperties.h:425
bool SerializeFromMismatchedTag(const FPropertyTag &Tag, FArchive &Ar)
Definition PerPlatformProperties.h:446
FPerPlatformFrameRate(FFrameRate InDefaultValue)
Definition PerPlatformProperties.h:441
FPerPlatformFrameRate()
Definition PerPlatformProperties.h:436
Definition PerPlatformProperties.h:211
FPerPlatformInt()
Definition PerPlatformProperties.h:222
FPerPlatformInt(int32 InDefaultValue)
Definition PerPlatformProperties.h:227
Definition PropertyTag.h:38
Definition TopLevelAssetPath.h:38
static void SerializePerPlatformMap(FArchive &UnderlyingArchive, FStructuredArchive::FRecord &Record, TMemoryImageMap< FMemoryImageName, ValueType > &Map)
Definition PerPlatformProperties.h:81
static void SerializePerPlatformMap(FArchive &Ar, TMemoryImageMap< FMemoryImageName, ValueType > &Map)
Definition PerPlatformProperties.h:57
static FMemoryImageName NameToKey(FName Name)
Definition PerPlatformProperties.h:54
static void SerializePerPlatformMap(FArchive &UnderlyingArchive, FStructuredArchive::FRecord &Record, TMap< FName, ValueType > &Map)
Definition PerPlatformProperties.h:45
static void SerializePerPlatformMap(FArchive &Ar, TMap< FName, ValueType > &Map)
Definition PerPlatformProperties.h:39
static FName NameToKey(FName Name)
Definition PerPlatformProperties.h:36
Definition PerPlatformProperties.h:31
Definition PerPlatformProperties.h:26
typename TTupleElement< 0, typename MapType::ElementType >::Type Type
Definition PerPlatformProperties.h:27
Definition PerPlatformProperties.h:116
bool Serialize(FArchive &Ar)
Definition PerPlatformProperties.h:183
_ValueType GetDefault() const
Definition PerPlatformProperties.h:144
_ValueType ValueType
Definition PerPlatformProperties.h:117
_StructType StructType
Definition PerPlatformProperties.h:118
bool SerializeFromMismatchedTag(const FPropertyTag &Tag, FArchive &Ar)
Definition PerPlatformProperties.h:169
_ValueType GetValue() const
Definition PerPlatformProperties.h:150
bool Serialize(FStructuredArchive::FSlot Slot)
Definition PerPlatformProperties.h:190
Definition StructOpsTypeTraits.h:11
Definition StructOpsTypeTraits.h:46
Definition Tuple.h:652