UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
LevelInstanceSubsystem.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2#pragma once
3
5#include "Containers/Array.h"
6#include "Containers/Map.h"
7#include "UObject/NameTypes.h"
8#include "UObject/GCObject.h"
9#include "Folder.h"
16
17#if WITH_EDITOR
18#include "EditorLevelUtils.h"
20#endif
21
22#include "LevelInstanceSubsystem.generated.h"
23
30class UBlueprint;
32
34{
35 None = 0,
36
46 KeepFolders = 1 << 0,
47};
49
53UCLASS(MinimalAPI)
55{
57
58public:
61
62 //~ Begin UObject Interface
63 static ENGINE_API void AddReferencedObjects(UObject* InThis, FReferenceCollector& Collector);
64 //~ End UObject Interface
65
66 //~ Begin USubsystem Interface.
68 ENGINE_API virtual void Deinitialize();
69 ENGINE_API virtual bool DoesSupportWorldType(EWorldType::Type WorldType) const override;
70 //~ End USubsystem Interface.
71
72 //~Begin IStreamingWorldSubsystemInterface
73 ENGINE_API virtual void OnUpdateStreamingState() override;
74 //~End IStreamingWorldSubsystemInterface
75
76 ENGINE_API ILevelInstanceInterface* GetLevelInstance(const FLevelInstanceID& LevelInstanceID) const;
77 ENGINE_API ILevelInstanceInterface* GetOwningLevelInstance(const ULevel* Level) const;
79 ENGINE_API static ULevel* GetOwningLevel(const ULevel* Level, bool bFollowChainToNonLevelInstanceOwningLevel = false);
80 ENGINE_API void UnregisterLevelInstance(ILevelInstanceInterface* LevelInstance);
81 ENGINE_API void RequestLoadLevelInstance(ILevelInstanceInterface* LevelInstance, bool bUpdate);
82 ENGINE_API void RequestUnloadLevelInstance(ILevelInstanceInterface* LevelInstance);
83 ENGINE_API bool IsLoaded(const ILevelInstanceInterface* LevelInstance) const;
85 ENGINE_API void ForEachLevelInstanceAncestors(const AActor* Actor, TFunctionRef<bool(const ILevelInstanceInterface*)> Operation) const;
86 ENGINE_API void ForEachLevelInstanceAncestors(AActor* Actor, TFunctionRef<bool(ILevelInstanceInterface*)> Operation) const;
87 ENGINE_API void ForEachLevelInstanceAncestorsAndSelf(AActor* Actor, TFunctionRef<bool(ILevelInstanceInterface*)> Operation) const;
89 ENGINE_API void ForEachLevelInstanceAncestorsAndSelf(const AActor* Actor, TFunctionRef<bool(const ILevelInstanceInterface*)> Operation) const;
90 ENGINE_API ULevelStreamingLevelInstance* GetLevelInstanceLevelStreaming(const ILevelInstanceInterface* LevelInstance) const;
91 ENGINE_API void ForEachActorInLevelInstance(const ILevelInstanceInterface* LevelInstance, TFunctionRef<bool(AActor* LevelActor)> Operation) const;
92 ENGINE_API ULevel* GetLevelInstanceLevel(const ILevelInstanceInterface* LevelInstance) const;
94 static ENGINE_API bool CanUseWorldAsset(const ILevelInstanceInterface* LevelInstance, TSoftObjectPtr<UWorld> WorldAsset, FString* OutReason);
100 static ENGINE_API bool CheckForLoop(const ILevelInstanceInterface* LevelInstance, TSoftObjectPtr<UWorld> WorldAsset, TArray<TPair<FText, TSoftObjectPtr<UWorld>>>* LoopInfo = nullptr, const ILevelInstanceInterface** LoopStart = nullptr);
101
102#if WITH_EDITOR
103 ENGINE_API void Tick();
104 ENGINE_API void OnExitEditorMode();
105 ENGINE_API void OnTryExitEditorMode();
106
107 UE_DEPRECATED(5.3, "Use FPackedLevelActorUtils::PackAllLoadedActors")
108 void PackAllLoadedActors() {}
109 UE_DEPRECATED(5.3, "Use FPackedLevelActorUtils::CanPackAllLoadedActors")
110 bool CanPackAllLoadedActors() const { return false;}
111
119
123
124 ENGINE_API void ForEachLevelInstanceChild(const ILevelInstanceInterface* LevelInstance, bool bRecursive, TFunctionRef<bool(const ILevelInstanceInterface*)> Operation) const;
127
130
139
140 ENGINE_API bool CanMoveActorToLevel(const AActor* Actor, FText* OutReason = nullptr) const;
142
144
148
151
153
154 // Returns the upper chain of level instance actors for the specified level starting with the level instance referencing the level
155 ENGINE_API void ForEachLevelInstanceActorAncestors(const ULevel* Level, TFunctionRef<bool(AActor*)> Operation) const;
157 ENGINE_API FString PrefixWithParentLevelInstanceActorLabels(const FString& ActorLabel, const ULevel* Level) const;
158
159 static ENGINE_API bool CheckForLoop(const ILevelInstanceInterface* LevelInstance, TArray<TPair<FText, TSoftObjectPtr<UWorld>>>* LoopInfo = nullptr, const ILevelInstanceInterface** LoopStart = nullptr);
160
161 UE_DEPRECATED(5.3, "CanUsePackage is deprecated.")
162 static bool CanUsePackage(FName InPackageName) { return true; }
163
167
171
174
175 static ENGINE_API void ResetLoadersForWorldAsset(const FString& WorldAsset);
176
178
180
181 ENGINE_API bool IsSubSelectionEnabled() const;
182private:
183 friend class FLevelInstanceEditorModule;
186 friend struct FLevelInstanceMenuUtils;
187 friend class ILevelInstanceInterface;
188 friend class ULevelInstanceEditorMode;
192
193 // EditPropertyOverrides
205
206 ENGINE_API static void RegisterPrimitiveColorHandler();
207 ENGINE_API static void UnregisterPrimitiveColorHandler();
208
210#endif
212
213private:
214 ENGINE_API void UpdateStreamingStateInternal();
215 ENGINE_API void BlockOnLoading();
216 ENGINE_API void LoadLevelInstance(ILevelInstanceInterface* LevelInstance);
217 ENGINE_API void UnloadLevelInstance(const FLevelInstanceID& LevelInstanceID);
218 ENGINE_API void ForEachActorInLevel(ULevel* Level, TFunctionRef<bool(AActor * LevelActor)> Operation) const;
219 ENGINE_API void RegisterLoadedLevelStreamingLevelInstance(ULevelStreamingLevelInstance* LevelStreaming);
220
221#if WITH_EDITOR
222 ENGINE_API ULevelStreamingLevelInstanceEditor* CreateNewStreamingLevelForWorld(UWorld& InWorld, const EditorLevelUtils::FCreateNewStreamingLevelForWorldParams& InParams);
223
225 ENGINE_API void OnAssetsPreDelete(const TArray<UObject*>& Objects);
228 void OnWorldCleanup(UWorld* InWorld, bool bSessionEnded, bool bCleanupResources);
229
231
232 ENGINE_API void OnEditChild(const FLevelInstanceID& LevelInstanceID);
233 ENGINE_API void OnCommitChild(const FLevelInstanceID& LevelInstanceID, bool bChildChanged);
234
237
239
241
243 {
244 public:
248
251
252 UWorld* GetEditWorld() const;
253 ILevelInstanceInterface* GetLevelInstance() const;
254
255 void AddReferencedObjects(FReferenceCollector& Collector);
256
258 bool CanDiscard(FText* OutReason = nullptr) const;
259 bool HasCommittedChanges() const;
261 };
262
264 {
265 public:
268
270
271 ILevelInstanceInterface* GetLevelInstance() const;
272 bool CanDiscard(FText* OutReason = nullptr) const { return true; }
273 bool IsDirty() const;
275 };
276
280
283
288
289 void OnExitEditorModeInternal(bool bForceExit);
290 bool TryCommitLevelInstanceEdit(bool bForceExit);
291 bool TryCommitLevelInstancePropertyOverrideEdit(bool bForceExit);
292
297
301
302 void ForEachLevelStreaming(TFunctionRef<bool(ULevelStreaming*)> Operation) const;
303
304 FString GetActorNameToSelectFromContext(const ILevelInstanceInterface* LevelInstance, const AActor* ContextActor, const FString& DefaultName = FString()) const;
305 void SelectActorFromActorName(ILevelInstanceInterface* LevelInstance, const FString& ActorName) const;
306
308 {
311 bool IsValid() const { return !bIsBeingDestroyed; }
312
313 TArray<ULevel*> Levels;
315 bool bResetTrans = false;
316 bool bIsBeingDestroyed = false;
317 };
318
319 ENGINE_API void RemoveLevelsFromWorld(const TArray<ULevel*>& Levels, bool bResetTrans = true);
320
321private:
322#endif
323
324#if WITH_EDITOR
327
331
333#endif
334
335 struct FLevelInstance
336 {
338 };
339
340 TMap<ILevelInstanceInterface*, bool> LevelInstancesToLoadOrUpdate;
341 TSet<FLevelInstanceID> LevelInstancesToUnload;
342 TSet<FLevelInstanceID> LoadingLevelInstances;
343 TMap<FLevelInstanceID, FLevelInstance> LoadedLevelInstances;
345
346#if WITH_EDITORONLY_DATA
347 // Optional scope to accelerate level unload by batching them
349
352
354
356#endif
357};
#define UE_DEPRECATED(Version, Message)
Definition CoreMiscDefines.h:302
FPlatformTypes::TCHAR TCHAR
Either ANSICHAR or WIDECHAR, depending on whether the platform supports wide characters or the requir...
Definition Platform.h:1135
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
#define DECLARE_EVENT_TwoParams(OwningType, EventName, Param1Type, Param2Type)
Definition DelegateCombinations.h:60
#define ENUM_CLASS_FLAGS(Enum)
Definition EnumClassFlags.h:6
ELevelInstanceBreakFlags
Definition LevelInstanceSubsystem.h:34
uint32 ERenameFlags
Definition ObjectMacros.h:2302
#define GENERATED_BODY(...)
Definition ObjectMacros.h:765
#define UCLASS(...)
Definition ObjectMacros.h:776
bool IsLoading()
Definition UObjectGlobals.cpp:2087
uint8_t uint8
Definition binka_ue_file_header.h:8
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition Actor.h:257
Definition NameTypes.h:617
Definition ObjectSaveContext.h:244
Definition UObjectGlobals.h:2492
Definition SubsystemCollection.h:15
Definition Text.h:385
Definition LevelInstanceInterface.h:33
Definition StreamingWorldSubsystemInterface.h:16
Definition Array.h:670
Definition AssetRegistryState.h:50
Definition UnrealString.h.inl:34
Definition UniquePtr.h:107
Definition Blueprint.h:403
Definition LevelInstanceEditorObject.h:18
Definition LevelInstancePropertyOverrideAsset.h:32
Definition LevelInstanceSubsystem.h:55
Definition LevelInstanceEditorPropertyOverrideLevelStreaming.h:20
Definition LevelInstanceEditorLevelStreaming.h:16
Definition LevelInstanceLevelStreaming.h:21
Definition LevelStreaming.h:139
TSoftObjectPtr< UWorld > WorldAsset
Definition LevelStreaming.h:203
Definition Level.h:423
Definition Object.h:95
Definition Package.h:216
Definition WorldPartitionSubsystem.h:52
Definition WorldSubsystem.h:16
Definition World.h:918
Type
Definition EngineTypes.h:1264
Definition AsyncRegisterLevelContext.cpp:16
Definition WorldPartitionActorContainerID.h:44
Definition WorldPartitionPropertyOverride.h:52
Definition LevelInstanceTypes.h:14
Definition LevelInstanceTypes.h:85
Definition ObjectPtr.h:488
Definition SoftObjectPtr.h:174
Definition Tuple.h:652
Definition WeakObjectPtrTemplates.h:25