UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
ActorDescContainerCollection.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2#pragma once
3
4#include "CoreMinimal.h"
5#include "UObject/Object.h"
7#include <type_traits>
8
11
12template<class ActorDescContPtrType>
14{
15#if WITH_EDITOR
16public:
17 template<class> friend class TActorDescContainerCollection;
18
20
21 template<class U>
23
24 template<class U>
26
28
29 void AddContainer(ActorDescContPtrType Container);
31 bool Contains(const FName& ContainerPackageName) const;
32 ActorDescContPtrType FindContainer(const FName& ContainerPackageName) const;
33
34 template<class U>
36
37 void Empty();
38 bool IsEmpty() const { return ActorDescContainerCollection.IsEmpty(); }
40
43
46
47 const FWorldPartitionActorDesc* GetActorDescByPath(const FString& ActorPath) const;
48 const FWorldPartitionActorDesc* GetActorDescByPath(const FSoftObjectPath& ActorPath) const;
50
51 bool RemoveActor(const FGuid& ActorGuid)
52 requires (!std::is_const_v<std::remove_pointer_t<ActorDescContPtrType>>);
53
55 requires (!std::is_const_v<std::remove_pointer_t<ActorDescContPtrType>>);
56
57 bool IsActorDescHandled(const AActor* Actor) const
58 requires (!std::is_const_v<std::remove_pointer_t<ActorDescContPtrType>>);
59
61 requires (!std::is_const_v<std::remove_pointer_t<ActorDescContPtrType>>);
62
65
68
69 ActorDescContPtrType GetActorDescContainer(const FGuid& ActorGuid) const;
70
72
75
78
79protected:
80 virtual void OnCollectionChanged() {};
81
83
84private:
85 void RegisterDelegates(ActorDescContPtrType Container);
86 void UnregisterDelegates(ActorDescContPtrType Container);
87
90
91public:
92 template<bool bConst, class ActorType>
93 class TBaseIterator
94 {
95 static_assert(TIsDerivedFrom<ActorType, AActor>::IsDerived, "Type is not derived from AActor.");
96
97 protected:
98 typedef UActorDescContainer ContainerType;
100 typedef std::conditional_t<bConst, typename ContainerCollectionType::TConstIterator, typename ContainerCollectionType::TIterator> ContainerIteratorType;
101 typedef std::conditional_t<bConst, typename ContainerType::TConstIterator<ActorType>, typename ContainerType::TIterator<ActorType>> ActDescIteratorType;
102
103 typedef typename FWorldPartitionActorDescType<ActorType>::Type ValueType;
104 typedef std::conditional_t<bConst, const ValueType*, ValueType*> ReturnType;
105
106 public:
107 template<class T>
108 TBaseIterator(T* Collection)
109 : ContainerIterator(Collection->ActorDescContainerCollection)
110 {
112 {
114 }
115 }
116
120 void operator++()
121 {
122 ++(*ActorsIterator);
123
124 if (!*ActorsIterator)
125 {
127 }
128 }
129
135 inline ReturnType operator*() const
136 {
138 }
139
145 inline ReturnType operator->() const
146 {
148 }
155 inline explicit operator bool() const
156 {
157 return ActorsIterator ? (bool)*ActorsIterator : false;
158 }
159
160 protected:
162 {
163 while (!(*ActorsIterator) && ContainerIterator)
164 {
167 {
169 }
170 }
171 }
172
175 };
176
177 template <class ActorType = AActor>
178 class TIterator : public TBaseIterator<false, ActorType>
179 {
180 typedef TBaseIterator<false, ActorType> BaseType;
181
182 public:
183 template<class T>
185 : BaseType(Collection)
186 {}
187 };
188
189 template <class ActorType = AActor>
190 class TConstIterator : public TBaseIterator<true, ActorType>
191 {
192 typedef TBaseIterator<true, ActorType> BaseType;
193
194 public:
195 template<class T>
197 : BaseType(Collection)
198 {}
199 };
200#endif
201};
202
203#if WITH_EDITOR
204
205template<class ActorDescContPtrType>
206template<class U>
209{
211 {
212 RegisterDelegates(ActorDescContainer);
213 });
214}
215
216template<class ActorDescContPtrType>
217template<class U>
220{
222 {
223 RegisterDelegates(ActorDescContainer);
224 });
225}
226
227template<class ActorDescContPtrType>
229{
230 Empty();
231}
232
233template<class ActorDescContPtrType>
235{
237 RegisterDelegates(Container);
238 OnCollectionChanged();
239}
240
241template<class ActorDescContPtrType>
243{
244 if (ActorDescContainerCollection.RemoveSwap(Container) > 0)
245 {
246 UnregisterDelegates(Container);
247 OnCollectionChanged();
248 return true;
249 }
250 return false;
251}
252
253template<class ActorDescContPtrType>
254template<class U>
256{
257 if (OtherCollection.IsEmpty())
258 {
259 return;
260 }
261
262 ActorDescContainerCollection.Append(OtherCollection.ActorDescContainerCollection);
263 int32 AppendedContainerIndex = ActorDescContainerCollection.Num() - OtherCollection.ActorDescContainerCollection.Num();
265 {
267 }
268
269 OnCollectionChanged();
270}
271
272template<class ActorDescContPtrType>
274{
275 return FindContainer(ContainerPackageName) != nullptr;
276}
277
278template<class ActorDescContPtrType>
280{
281 auto ContainerPtr = ActorDescContainerCollection.FindByPredicate([&ContainerPackageName](ActorDescContPtrType ActorDescContainer) { return ActorDescContainer->GetContainerPackage() == ContainerPackageName; });
282 return ContainerPtr != nullptr ? *ContainerPtr : nullptr;
283}
284
285template<class ActorDescContPtrType>
287{
289 {
290 UnregisterDelegates(ActorDescContainer);
291 });
292
294 OnCollectionChanged();
295}
296
297template<class ActorDescContPtrType>
299{
301 ConstCast(Container)->OnActorDescRemovedEvent.AddRaw(this, &TActorDescContainerCollection::OnActorDescRemoved);
302}
303
304template<class ActorDescContPtrType>
306{
307 ConstCast(Container)->OnActorDescAddedEvent.RemoveAll(this);
308 ConstCast(Container)->OnActorDescRemovedEvent.RemoveAll(this);
309}
310
311template<class ActorDescContPtrType>
313{
314 const FWorldPartitionActorDesc* ActorDesc = nullptr;
316 {
317 ActorDesc = ActorDescContainer->GetActorDesc(Guid);
318 return ActorDesc == nullptr;
319 });
320
321 return ActorDesc;
322}
323
324template<class ActorDescContPtrType>
326{
327 return const_cast<FWorldPartitionActorDesc*>(const_cast<const TActorDescContainerCollection*>(this)->GetActorDesc(Guid));
328}
329
330template<class ActorDescContPtrType>
332{
334 check(ActorDesc != nullptr);
335
337 return ActorDesc != nullptr ? *ActorDesc : EmptyDescriptor;
338}
339
340template<class ActorDescContPtrType>
342{
343 return const_cast<FWorldPartitionActorDesc&>(const_cast<const TActorDescContainerCollection*>(this)->GetActorDescChecked(Guid));
344}
345
346template<class ActorDescContPtrType>
348{
349 const FWorldPartitionActorDesc* ActorDesc = nullptr;
351 {
352 ActorDesc = ActorDescContainer->GetActorDescByPath(ActorPath);
353 return ActorDesc == nullptr;
354 });
355
356 return ActorDesc;
357}
358
359template<class ActorDescContPtrType>
361{
362 const FWorldPartitionActorDesc* ActorDesc = nullptr;
364 {
365 ActorDesc = ActorDescContainer->GetActorDescByPath(ActorPath);
366 return ActorDesc == nullptr;
367 });
368
369 return ActorDesc;
370}
371
372template<class ActorDescContPtrType>
374{
375 const FWorldPartitionActorDesc* ActorDesc = nullptr;
377 {
378 ActorDesc = ActorDescContainer->GetActorDescByName(ActorName);
379 return ActorDesc == nullptr;
380 });
381
382 return ActorDesc;
383}
384
385template<class ActorDescContPtrType>
387 requires (!std::is_const_v<std::remove_pointer_t<ActorDescContPtrType>>)
388{
389 bool bRemoved = false;
391 {
392 bRemoved = ActorDescContainer->RemoveActor(ActorGuid);
393 return !bRemoved;
394 });
395
396 return bRemoved;
397}
398
399template<class ActorDescContPtrType>
401 requires (!std::is_const_v<std::remove_pointer_t<ActorDescContPtrType>>)
402{
404 {
405 ActorDescContainer->OnPackageDeleted(Package);
406 });
407}
408
409template<class ActorDescContPtrType>
411 requires (!std::is_const_v<std::remove_pointer_t<ActorDescContPtrType>>)
412{
413 bool bIsHandled = false;
415 {
416 bIsHandled = ActorDescContainer->IsActorDescHandled(Actor);
417 return !bIsHandled;
418 });
419
420 return bIsHandled;
421}
422
423template<class ActorDescContPtrType>
425 requires (!std::is_const_v<std::remove_pointer_t<ActorDescContPtrType>>)
426{
428 {
429 ActorDescContainer->LoadAllActors(OutReferences);
430 });
431}
432
433template<class ActorDescContPtrType>
435{
438 {
439 if (InActorDescContainer->GetActorDesc(ActorGuid) != nullptr)
440 {
441 ActorDescContainer = InActorDescContainer;
442 }
443 return ActorDescContainer == nullptr;
444 });
445
446 return ActorDescContainer;
447}
448
449template<class ActorDescContPtrType>
451{
452 // Actor is already in a container
453 if (ActorDescContPtrType ActorDescContainer = GetActorDescContainer(Actor->GetActorGuid()))
454 {
455 return ActorDescContainer;
456 }
457
458 // Actor is not yet stored in a container. Find which one should handle it.
461 {
462 if (InActorDescContainer->IsActorDescHandled(Actor))
463 {
464 ActorDescContainer = InActorDescContainer;
465 }
466 return ActorDescContainer == nullptr;
467 });
468
469 return ActorDescContainer;
470}
471
472template<class ActorDescContPtrType>
474{
476 {
477 if (!Func(ActorDescContainer))
478 {
479 break;
480 }
481 }
482}
483
484template<class ActorDescContPtrType>
486{
488}
489
490template<class ActorDescContPtrType>
492{
494 {
495 Func(ActorDescContainer);
496 }
497}
498
499template<class ActorDescContPtrType>
501{
502 const_cast<const TActorDescContainerCollection*>(this)->ForEachActorDescContainer(Func);
503}
504
505template<class ActorDescContPtrType>
507{
509}
510
511template<class ActorDescContPtrType>
513{
515}
516
517#endif
518
#define check(expr)
Definition AssertionMacros.h:314
UE_FORCEINLINE_HINT FLinearColor operator*(float Scalar, const FLinearColor &Color)
Definition Color.h:473
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 DECLARE_EVENT_OneParam(OwningType, EventName, Param1Type)
Definition DelegateCombinations.h:51
const bool
Definition NetworkReplayStreaming.h:178
FORCEINLINE decltype(auto) ConstCast(const TObjectPtr< T > &P)
Definition ObjectPtr.h:1778
TIndexedContainerIterator< const TArray< FPreviewAttachedObjectPair >, const FPreviewAttachedObjectPair, int32 > TConstIterator
Definition PreviewAssetAttachComponent.h:69
TIndexedContainerIterator< TArray< FPreviewAttachedObjectPair >, FPreviewAttachedObjectPair, int32 > TIterator
Definition PreviewAssetAttachComponent.h:68
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition Actor.h:257
Definition NameTypes.h:617
Definition UObjectGlobals.h:2492
Definition WorldPartitionActorDesc.h:282
Definition ActorDescContainerCollection.h:14
Definition Array.h:670
Definition AssetRegistryState.h:50
Definition Array.h:64
Definition UniquePtr.h:107
Definition ActorDescContainer.h:40
Definition Package.h:216
Definition WorldPartition.h:142
Definition Guid.h:109
Definition SoftObjectPath.h:56
Definition UnrealTypeTraits.h:40