UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
TopLevelAssetPath.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
8#include "CoreTypes.h"
13#include "Templates/TypeHash.h"
14#include "Traits/IsCharType.h"
15#include "UObject/NameTypes.h"
17
18#include <type_traits>
19
20#include "TopLevelAssetPath.generated.h"
21
22class FCbWriter;
23struct FPropertyTag;
24class FCbWriter;
25class FString;
26class UObject;
27
28/*
29 * A struct that can reference a top level asset such as '/Path/To/Package.AssetName'
30 * Stores two FNames internally to avoid
31 * a) storing a concatenated FName that bloats global FName storage
32 * b) storing an empty FString for a subobject path as FSoftObjectPath allows
33 * Can also be used to reference the package itself in which case the second name is NAME_None
34 * and the object resolves to the string `/Path/To/Package`
35*/
36USTRUCT(BlueprintType, meta = (HasNativeMake = "/Script/Engine.KismetSystemLibrary.MakeTopLevelAssetPath", HasNativeBreak = "/Script/Engine.KismetSystemLibrary.BreakTopLevelAssetPath"))
38{
40public:
43
49
50 UE_DEPRECATED(5.0, "FNames containing full asset paths have been replaced by FTopLevelAssetPath/FSoftLevelObjectPath."
51 "This function is only for temporary use interfacing with APIs that still produce an FName."
52 "Those APIS should be updated to use FTopLevelAssetPath or FSoftLevelObjectPath.")
54 {
55 TrySetPath(InPath.ToString());
56 }
57
59 explicit FTopLevelAssetPath(const FString& Path) { TrySetPath(FStringView(Path)); }
61 explicit FTopLevelAssetPath(TStringView<CharType> Path) { TrySetPath(Path); }
63 explicit FTopLevelAssetPath(const CharType* Path) { TrySetPath(TStringView<CharType>(Path)); }
64
66 explicit FTopLevelAssetPath(const UObject* InObject) { TrySetPath(InObject); }
67
69 FTopLevelAssetPath& operator=(const FString& Path) { TrySetPath(FStringView(Path)); return *this; }
70 template<typename CharType>
71 FTopLevelAssetPath& operator=(TStringView<CharType> Path) { TrySetPath(Path); return *this; }
73 FTopLevelAssetPath& operator=(const CharType* Path) { TrySetPath(TStringView<CharType>(Path)); return *this; }
75
79 COREUOBJECT_API bool TrySetPath(const UObject* InObject);
81 COREUOBJECT_API bool TrySetPath(FWideStringView Path);
82 COREUOBJECT_API bool TrySetPath(FUtf8StringView Path);
83 COREUOBJECT_API bool TrySetPath(FAnsiStringView Path);
85 bool TrySetPath(const CharType* Path) { return TrySetPath(TStringView<CharType>(Path)); }
86 bool TrySetPath(const FString& Path) { return TrySetPath(FStringView(Path)); }
87
90
92 FName GetPackageName() const { return PackageName; }
93
95 FName GetAssetName() const { return AssetName; }
96
98 COREUOBJECT_API void AppendString(FWideStringBuilderBase& Builder) const;
99 COREUOBJECT_API void AppendString(FUtf8StringBuilderBase& Builder) const;
101 COREUOBJECT_API void AppendString(FString& OutString) const;
102
104 COREUOBJECT_API FString ToString() const;
106 COREUOBJECT_API void ToString(FString& OutString) const;
107
108 // Return the full asset path (e.g. '/Path/To/Package.AssetName') as an FName.
109 UE_DEPRECATED(5.1, "FNames containing full asset paths have been replaced by FTopLevelAssetPath/FSoftLevelObjectPath."
110 "This function is only for temporary use interfacing with APIs that still expect an FName."
111 "Those APIS should be updated to use FTopLevelAssetPath or FSoftLevelObjectPath.")
112 FName ToFName() const { return *ToString(); }
113
115 bool IsValid() const
116 {
117 return !PackageName.IsNone();
118 }
119
121 bool IsNull() const
122 {
123 return PackageName.IsNone();
124 }
125
127 void Reset()
128 {
129 PackageName = AssetName = FName();
130 }
133 {
134 return PackageName == Other.PackageName && AssetName == Other.AssetName;
135 }
136
139 {
140 return !(*this == Other);
141 }
142
145 {
146 return Ar << Path.PackageName << Path.AssetName;
147 }
148
151 {
153 Record << SA_VALUE(TEXT("PackageName"), Path.PackageName) << SA_VALUE(TEXT("AssetName"), Path.AssetName);
154 }
155
158 {
159 if (int32 Diff = PackageName.Compare(Other.PackageName))
160 {
161 return Diff;
162 }
163 return AssetName.Compare(Other.AssetName);
164 }
165
168 {
169 if (int32 Diff = PackageName.CompareIndexes(Other.PackageName))
170 {
171 return Diff;
172 }
173 return AssetName.CompareIndexes(Other.AssetName);
174 }
175
177 {
178 return HashCombineFast(GetTypeHash(This.PackageName), GetTypeHash(This.AssetName));
179 }
180
181 COREUOBJECT_API bool ExportTextItem(FString& ValueStr, FTopLevelAssetPath const& DefaultValue, UObject* Parent, int32 PortFlags, UObject* ExportRootScope) const;
182 COREUOBJECT_API bool ImportTextItem( const TCHAR*& Buffer, int32 PortFlags, UObject* Parent, FOutputDevice* ErrorText, FArchive* InSerializingArchive = nullptr );
183 COREUOBJECT_API bool SerializeFromMismatchedTag(const FPropertyTag& Tag, FStructuredArchive::FSlot Slot);
184
185 COREUOBJECT_API void WriteCompactBinary(FCbWriter& Writer) const;
186private:
187 friend FCbWriter& operator<<(FCbWriter& Writer, const FTopLevelAssetPath& Path)
188 {
189 Path.WriteCompactBinary(Writer);
190 return Writer;
191 }
193
195 UPROPERTY(EditAnywhere, SaveGame, BlueprintReadWrite, Category = TopLevelAssetPath, meta = (AllowPrivateAccess = "true"))
196 FName PackageName;
198 UPROPERTY(EditAnywhere, SaveGame, BlueprintReadWrite, Category = TopLevelAssetPath, meta = (AllowPrivateAccess = "true"))
199 FName AssetName;
200
202};
203
205{
206 Path.AppendString(Builder);
207 return Builder;
208}
209
211{
212 Path.AppendString(Builder);
213 return Builder;
214}
215
218{
220 {
221 return A.CompareFast(B) < 0;
222 }
223};
224
227{
229 {
230 return A.Compare(B) < 0;
231 }
232};
233
234template<>
bool LoadFromCompactBinary(FCbFieldView Field, FAssetDependency &Dependency)
Definition AssetRegistry.cpp:10420
#define TEXT(x)
Definition Platform.h:1272
FPlatformTypes::TYPE_OF_NULLPTR TYPE_OF_NULLPTR
The type of the C++ nullptr keyword.
Definition Platform.h:1157
FPlatformTypes::TCHAR TCHAR
Either ANSICHAR or WIDECHAR, depending on whether the platform supports wide characters or the requir...
Definition Platform.h:1135
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
return true
Definition ExternalRpcRegistry.cpp:601
void SerializeForLog(FCbWriter &Writer, const FIoStatus &Status)
Definition IoStatus.cpp:107
#define UPROPERTY(...)
UObject definition macros.
Definition ObjectMacros.h:744
#define GENERATED_BODY(...)
Definition ObjectMacros.h:765
#define USTRUCT(...)
Definition ObjectMacros.h:746
TStringView< TCHAR > FStringView
Definition StringFwd.h:45
#define SA_VALUE(Name, Value)
Definition StructuredArchiveNameHelpers.h:77
FWideStringBuilderBase & operator<<(FWideStringBuilderBase &Builder, const FTopLevelAssetPath &Path)
Definition TopLevelAssetPath.h:204
constexpr uint32 HashCombineFast(uint32 A, uint32 B)
Definition TypeHash.h:74
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition Archive.h:1208
Definition CompactBinary.h:610
Definition CompactBinaryWriter.h:68
Definition NameTypes.h:617
Definition OutputDevice.h:133
Definition StructuredArchiveSlots.h:144
Definition StructuredArchiveSlots.h:52
UE_API FStructuredArchiveRecord EnterRecord()
Definition StructuredArchiveSlots.h:252
Definition StringBuilder.h:79
Definition StringView.h:107
Definition Object.h:95
Definition FieldSystemNoiseAlgo.cpp:6
Definition PropertyTag.h:38
Definition TopLevelAssetPath.h:218
UE_FORCEINLINE_HINT bool operator()(const FTopLevelAssetPath &A, const FTopLevelAssetPath &B) const
Definition TopLevelAssetPath.h:219
Definition TopLevelAssetPath.h:227
UE_FORCEINLINE_HINT bool operator()(const FTopLevelAssetPath &A, const FTopLevelAssetPath &B) const
Definition TopLevelAssetPath.h:228
Definition TopLevelAssetPath.h:38
FTopLevelAssetPath(const FString &Path)
Definition TopLevelAssetPath.h:59
int32 Compare(const FTopLevelAssetPath &Other) const
Definition TopLevelAssetPath.h:157
friend FArchive & operator<<(FArchive &Ar, FTopLevelAssetPath &Path)
Definition TopLevelAssetPath.h:144
friend uint32 GetTypeHash(FTopLevelAssetPath const &This)
Definition TopLevelAssetPath.h:176
bool operator==(FTopLevelAssetPath const &Other) const
Definition TopLevelAssetPath.h:132
bool IsValid() const
Definition TopLevelAssetPath.h:115
FTopLevelAssetPath & operator=(TStringView< CharType > Path)
Definition TopLevelAssetPath.h:71
bool operator!=(FTopLevelAssetPath const &Other) const
Definition TopLevelAssetPath.h:138
bool TrySetPath(const FString &Path)
Definition TopLevelAssetPath.h:86
FName GetPackageName() const
Definition TopLevelAssetPath.h:92
UE_DEPRECATED(5.0, "FNames containing full asset paths have been replaced by FTopLevelAssetPath/FSoftLevelObjectPath." "This function is only for temporary use interfacing with APIs that still produce an FName." "Those APIS should be updated to use FTopLevelAssetPath or FSoftLevelObjectPath.") explicit FTopLevelAssetPath(FName InPath)
Definition TopLevelAssetPath.h:50
FTopLevelAssetPath(const CharType *Path)
Definition TopLevelAssetPath.h:63
bool TrySetPath(const CharType *Path)
Definition TopLevelAssetPath.h:85
FTopLevelAssetPath(FName InPackageName, FName InAssetName)
Definition TopLevelAssetPath.h:45
FTopLevelAssetPath & operator=(const FString &Path)
Definition TopLevelAssetPath.h:69
void Reset()
Definition TopLevelAssetPath.h:127
int32 CompareFast(const FTopLevelAssetPath &Other) const
Definition TopLevelAssetPath.h:167
FTopLevelAssetPath & operator=(TYPE_OF_NULLPTR)
Definition TopLevelAssetPath.h:74
FTopLevelAssetPath(const UObject *InObject)
Definition TopLevelAssetPath.h:66
FTopLevelAssetPath()
Definition TopLevelAssetPath.h:41
FTopLevelAssetPath(TStringView< CharType > Path)
Definition TopLevelAssetPath.h:61
friend FCbWriter & operator<<(FCbWriter &Writer, const FTopLevelAssetPath &Path)
Definition TopLevelAssetPath.h:187
UE_DEPRECATED(5.1, "FNames containing full asset paths have been replaced by FTopLevelAssetPath/FSoftLevelObjectPath." "This function is only for temporary use interfacing with APIs that still expect an FName." "Those APIS should be updated to use FTopLevelAssetPath or FSoftLevelObjectPath.") FName ToFName() const
Definition TopLevelAssetPath.h:109
bool IsNull() const
Definition TopLevelAssetPath.h:121
friend void operator<<(FStructuredArchive::FSlot Slot, FTopLevelAssetPath &Path)
Definition TopLevelAssetPath.h:150
FTopLevelAssetPath(TYPE_OF_NULLPTR)
Definition TopLevelAssetPath.h:42
FName GetAssetName() const
Definition TopLevelAssetPath.h:95
FTopLevelAssetPath & operator=(const CharType *Path)
Definition TopLevelAssetPath.h:73
Definition StructOpsTypeTraits.h:11
@ WithStructuredSerializeFromMismatchedTag
Definition StructOpsTypeTraits.h:29
@ WithExportTextItem
Definition StructOpsTypeTraits.h:20
@ WithImportTextItem
Definition StructOpsTypeTraits.h:21
Definition StructOpsTypeTraits.h:46