UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
Folder.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "Misc/Guid.h"
7#include "UObject/Object.h"
8#include "UObject/ObjectKey.h"
10#include "Misc/Paths.h"
11#include "Misc/Optional.h"
12
13class ULevel;
14class UActorFolder;
15class UWorld;
16
17struct FFolder
18{
19#if WITH_EDITOR
20 typedef FObjectKey FRootObject;
21
22 // Only used by containers
23 FFolder()
24 : bPathInitialized(true)
25 , Path(GetEmptyPath())
26 , RootObject(GetInvalidRootObject())
27 {}
28
30 : bPathInitialized(true)
31 , Path(InPath)
32 , RootObject(InRootObject)
33 {
34 if (Path != GetEmptyPath())
35 {
37 TArray<FString> Parts;
38 Path.ToString().ParseIntoArray(Parts, TEXT("/"), true);
39 for (FString& Part : Parts)
40 {
41 if (Result.Len())
42 {
43 Result += TEXT("/");
44 }
45 Result += Part.TrimStartAndEnd();
46 }
47 Path = *Result;
48 }
49 }
50
52 : bPathInitialized(false)
53 , Path(NAME_None)
54 , RootObject(InRootObject)
56 {
57 check(ActorFolderGuid.IsValid());
58 }
59
61 {
62 return InRootObject.ResolveObjectPtr();
63 }
64
65 inline static bool IsRootObjectValid(const FRootObject& Key)
66 {
67 return Key != GetInvalidRootObject();
68 }
69
70 inline static FName GetEmptyPath()
71 {
72 return NAME_None;
73 }
74
75 inline bool IsRootObjectValid() const
76 {
77 return FFolder::IsRootObjectValid(RootObject);
78 }
79
81 {
82 return FFolder::GetRootObjectAssociatedLevel(RootObject);
83 }
84
85 inline bool IsRootObjectPersistentLevel() const
86 {
87 return FFolder::IsRootObjectPersistentLevel(RootObject);
88 }
89
90 inline bool IsValid() const
91 {
92 return IsRootObjectValid();
93 }
94
95 inline bool IsChildOf(const FFolder& InParent) const
96 {
97 if (RootObject != InParent.RootObject)
98 {
99 return false;
100 }
101 return PathIsChildOf(GetPath(), InParent.GetPath());
102 }
103
104 inline bool IsNone() const
105 {
106 return GetPath().IsNone();
107 }
108
109 inline const FRootObject& GetRootObject() const
110 {
111 return RootObject;
112 }
113
114 inline UObject* GetRootObjectPtr() const
115 {
116 return FFolder::GetRootObjectPtr(RootObject);
117 }
118
119 inline const FGuid& GetActorFolderGuid() const
120 {
121 return ActorFolderGuid;
122 }
123
124 inline FName GetLeafName() const
125 {
126 FName PathLocal = GetPath();
127 FString PathString = PathLocal.ToString();
128 int32 LeafIndex = 0;
129 if (PathString.FindLastChar('/', LeafIndex))
130 {
131 return FName(*PathString.RightChop(LeafIndex + 1));
132 }
133 else
134 {
135 return PathLocal;
136 }
137 }
138
139 inline bool operator == (const FFolder& InOther) const
140 {
141 return (RootObject == InOther.RootObject) && (GetPath() == InOther.GetPath()); // don't check for ActorFolderGuid as it's only used as an accelerator
142 }
143
144 inline bool operator != (const FFolder& InOther) const
145 {
146 return !operator==(InOther);
147 }
148
149 inline FString ToString() const
150 {
151 return GetPath().ToString();
152 }
153
154 inline friend FArchive& operator<<(FArchive& Ar, FFolder& Folder)
155 {
156 check(!Ar.IsPersistent());
157 return Ar << Folder.bPathInitialized << Folder.Path << Folder.RootObject << Folder.ActorFolderGuid;
158 }
159
160 ENGINE_API const FName GetPath() const;
161 ENGINE_API FFolder GetParent() const;
163
164 // Helpers methods
165 static ENGINE_API const FFolder& GetInvalidFolder();
167 static ENGINE_API bool IsRootObjectPersistentLevel(const FRootObject& Key);
172
173private:
174 bool PathIsChildOf(const FString& InPotentialChild, const FString& InParent) const
175 {
176 const int32 ParentLen = InParent.Len();
177
178 // If parent is empty and child isn't, consider that path is child of parent
179 if ((InPotentialChild.Len() > 0) && (ParentLen == 0))
180 {
181 return true;
182 }
183
184 return
185 InPotentialChild.Len() > ParentLen &&
186 InPotentialChild[ParentLen] == '/' &&
188 }
189
190 bool PathIsChildOf(const FName& InPotentialChild, const FName& InParent) const
191 {
192 return PathIsChildOf(InPotentialChild.ToString(), InParent.ToString());
193 }
194
195 mutable bool bPathInitialized;
196 mutable FName Path;
197 FRootObject RootObject;
198 mutable FGuid ActorFolderGuid; // Optional : Used to find Level's ActorFolder faster than by using the path
199
200 friend inline uint32 GetTypeHash(const FFolder& InFolder)
201 {
202 return HashCombine(GetTypeHash(InFolder.GetPath()), GetTypeHash(InFolder.GetRootObject()));
203 }
204#endif
205};
#define check(expr)
Definition AssertionMacros.h:314
#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
FArchive & operator<<(FArchive &Ar, FEnvQueryDebugProfileData::FStep &Data)
Definition EnvQueryTypes.cpp:489
UE_FORCEINLINE_HINT bool operator!=(const FIndexedPointer &Other) const
Definition LockFreeList.h:76
constexpr uint32 HashCombine(uint32 A, uint32 C)
Definition TypeHash.h:36
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition Archive.h:1208
UE_FORCEINLINE_HINT bool IsPersistent() const
Definition Archive.h:300
Definition NameTypes.h:617
Definition Array.h:670
Definition StringBuilder.h:509
Definition ActorFolder.h:17
CORE_API UE_STRING_CLASS TrimStartAndEnd() const &
Definition String.cpp.inl:904
UE_FORCEINLINE_HINT int32 Len() const
Definition UnrealString.h.inl:954
Definition Level.h:423
Definition Object.h:95
Definition World.h:918
CORE_API FString ToString() const
Definition Color.cpp:584
Definition Folder.h:18
Definition Guid.h:109
Definition ObjectKey.h:19
Definition Optional.h:131