UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
ActorDescList.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2#pragma once
3
4#include "CoreMinimal.h"
9
10#if WITH_EDITOR
11// Default Iterator Value Type is the DescType itself
12template<typename DescType, class ActorType>
14{
15 using Type = DescType;
16};
17#endif
18
19template<class DescType>
21{
22#if WITH_EDITOR
23 friend struct FWorldPartitionImplBase;
24
25 struct FActorGuidKeyFuncs : TDefaultMapKeyFuncs<FGuid, TUniquePtr<DescType>*, false>
26 {
27 static inline uint32 GetKeyHash(const FGuid& Key)
28 {
29 return HashCombineFast(HashCombineFast(Key.A, Key.B), HashCombineFast(Key.C, Key.D));
30 }
31 };
32
33protected:
36
37public:
38 TActorDescList() : bIsProxy(false) {}
39 virtual ~TActorDescList() {}
40
41 // Non-copyable
42 TActorDescList(const TActorDescList&) = delete;
43 TActorDescList& operator=(const TActorDescList&) = delete;
44
45 bool IsEmpty() const { return GetActorsByGuid().Num() == 0; }
46 void Empty()
47 {
48 check(!bIsProxy || ActorsByGuid.IsEmpty());
49 ActorsByGuid.Empty();
50 ActorDescList.Empty();
51 }
52
53 template<bool bConst, class ActorType>
54 class TBaseIterator
55 {
56 static_assert(TIsDerivedFrom<ActorType, AActor>::IsDerived, "Type is not derived from AActor.");
57
58 protected:
59 using MapType = FGuidActorDescMap;
60 using ValueType = typename TActorDescListIteratorValueType<DescType, ActorType>::Type;
61 using IteratorType = std::conditional_t<bConst, typename MapType::TConstIterator, typename MapType::TIterator>;
62 using ListType = std::conditional_t<bConst, const TActorDescList<DescType>*, TActorDescList<DescType>*>;
63 using ReturnType = std::conditional_t<bConst, const ValueType*, ValueType*>;
64
65 public:
66 TBaseIterator(ListType InActorDescList, UClass* InActorClass)
67 : ActorsIterator(InActorDescList->GetActorsByGuid())
68 , ActorClass(InActorClass)
69 , bIsProxy(InActorDescList->bIsProxy)
70 {
71 check(ActorClass->IsNative());
72 check(ActorClass->IsChildOf(ActorType::StaticClass()));
73
74 if (ShouldSkip())
75 {
76 operator++();
77 }
78 }
79
83 inline void operator++()
84 {
85 do
86 {
88 } while (ShouldSkip());
89 }
90
94 inline void RemoveCurrent()
95 {
97 ActorsIterator.RemoveCurrent();
98 }
99
105 inline ReturnType operator*() const
106 {
107 return StaticCast<ReturnType>(ActorsIterator->Value->Get());
108 }
109
115 inline ReturnType operator->() const
116 {
117 return StaticCast<ReturnType>(ActorsIterator->Value->Get());
118 }
119
126 inline explicit operator bool() const
127 {
128 return (bool)ActorsIterator;
129 }
130
136 inline UClass* GetActorClass() const { return ActorClass; }
137
138 protected:
143 inline bool ShouldSkip() const
144 {
145 if (!ActorsIterator)
146 {
147 return false;
148 }
149
150 return !ActorsIterator->Value->Get()->GetActorNativeClass()->IsChildOf(ActorClass);
151 }
152
153 IteratorType ActorsIterator;
154 UClass* ActorClass;
155 bool bIsProxy;
156 };
157
158 template <class ActorType = AActor>
159 class TIterator : public TBaseIterator<false, ActorType>
160 {
161 using BaseType = TBaseIterator<false, ActorType>;
162
163 public:
164 TIterator(typename BaseType::ListType InActorDescList, UClass* InActorClass = nullptr)
165 : BaseType(InActorDescList, InActorClass ? InActorClass : ActorType::StaticClass())
166 {}
167 };
168
169 template <class ActorType = AActor>
170 class TConstIterator : public TBaseIterator<true, ActorType>
171 {
172 using BaseType = TBaseIterator<true, ActorType>;
173
174 public:
175 TConstIterator(typename BaseType::ListType InActorDescList, UClass* InActorClass = nullptr)
176 : BaseType(InActorDescList, InActorClass ? InActorClass : ActorType::StaticClass())
177 {}
178 };
179
182
183 virtual FGuidActorDescMap& GetActorsByGuid() const { return GetProxyActorsByGuid(); }
184protected:
185 void SetIsProxy()
186 {
187 check(ActorsByGuid.IsEmpty());
188 bIsProxy = true;
189 }
190 // Allow Child class to Proxy to another list
191 virtual FGuidActorDescMap& GetProxyActorsByGuid() const { return const_cast<FGuidActorDescMap&>(ActorsByGuid); }
192
194 const TUniquePtr<DescType>* GetActorDescriptor(const FGuid& ActorGuid) const;
195
197 const TUniquePtr<DescType>* GetActorDescriptorChecked(const FGuid& ActorGuid) const;
198
201 bool bIsProxy;
202#endif
203};
204
205#if WITH_EDITOR
206template<class DescType>
208{
209 check(!bIsProxy);
211
213 {
214 UE_LOG(LogWorldPartition, Error, TEXT("Duplicated actor descriptor detected:\n\tExisting: %s\n\t New: %s"),
215 *ExistingActorDesc->Get()->ToString(FWorldPartitionActorDesc::EToStringMode::Full), *ActorDesc->ToString(FWorldPartitionActorDesc::EToStringMode::Full));
216 }
217 else
218 {
220 ActorsByGuid.Add(ActorDesc->GetGuid(), NewActorDesc);
221 }
222}
223
224template<class DescType>
226{
227 check(!bIsProxy);
229
230 if (!ensure((ActorsByGuid.Remove(ActorDesc->GetGuid()))))
231 {
232 UE_LOG(LogWorldPartition, Error, TEXT("Removing unknown actor descriptor: %s"), *ActorDesc->ToString(FWorldPartitionActorDesc::EToStringMode::Full));
233 }
234}
235
236template<class DescType>
238{
239 return GetProxyActorsByGuid().FindRef(ActorGuid);
240}
241
242template<class DescType>
244{
245 return GetProxyActorsByGuid().FindRef(ActorGuid);
246}
247
248template<class DescType>
250{
251 return GetProxyActorsByGuid().FindChecked(ActorGuid);
252}
253
254template<class DescType>
256{
257 return GetProxyActorsByGuid().FindChecked(ActorGuid);
258}
259
260// FActorDescList supports subclassing through ActorType's and FWorldPartitionActorDescType will return the proper iterator value type
261template<class ActorType>
263{
264 using Type = typename FWorldPartitionActorDescType<ActorType>::Type;
265};
266#endif
267
268class FActorDescList : public TActorDescList<FWorldPartitionActorDesc>
269{
270#if WITH_EDITOR
271public:
273 ENGINE_API virtual const FWorldPartitionActorDesc* GetActorDesc(const FGuid& Guid) const;
274
277
278 int32 GetActorDescCount() const { return GetProxyActorsByGuid().Num(); }
279
281#endif
282};
#define check(expr)
Definition AssertionMacros.h:314
#define ensure( InExpression)
Definition AssertionMacros.h:464
UE_FORCEINLINE_HINT FLinearColor operator*(float Scalar, const FLinearColor &Color)
Definition Color.h:473
#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 UE_LOG(CategoryName, Verbosity, Format,...)
Definition LogMacros.h:270
const bool
Definition NetworkReplayStreaming.h:178
TIndexedContainerIterator< const TArray< FPreviewAttachedObjectPair >, const FPreviewAttachedObjectPair, int32 > TConstIterator
Definition PreviewAssetAttachComponent.h:69
TIndexedContainerIterator< TArray< FPreviewAttachedObjectPair >, FPreviewAttachedObjectPair, int32 > TIterator
Definition PreviewAssetAttachComponent.h:68
constexpr uint32 HashCombineFast(uint32 A, uint32 B)
Definition TypeHash.h:74
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition Actor.h:257
Definition ActorDescList.h:269
Definition ContainerAllocationPolicies.h:1660
Definition WorldPartitionActorDesc.h:282
Definition ActorDescList.h:21
Definition ChunkedArray.h:56
Definition Array.h:64
Definition UnrealString.h.inl:34
Definition UniquePtr.h:107
Definition Class.h:3793
bool IsChildOf() const
Definition Class.h:788
Type
Definition PawnAction_Move.h:11
Definition Guid.h:109
Definition Map.h:77
Definition UnrealTypeTraits.h:40