UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
DefaultManagerInstanceTracker.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "Containers/Map.h"
6#include "Engine/World.h"
7
8
10
11template<typename FManager>
13{
15 bool bCreateIfMissing = false;
16
17 UE_DEPRECATED(5.1, "TDefaultManagerInstanceTracker is deprecated and will be removed. Consider inheriting from a subsystem instead.")
21
22 UE_DEPRECATED(5.1, "TDefaultManagerInstanceTracker is deprecated and will be removed. Consider inheriting from a subsystem instead.")
24 {
25 FManager** FoundInstance = WorldToInstanceMap.Find(&World);
26 if (FoundInstance)
27 {
28 return *FoundInstance;
29 }
30 else if (World.bIsTearingDown)
31 {
32 return nullptr;
33 }
34
35 FManager* NewInstance = nullptr;
37 {
39 NewInstance->AddToRoot();
41 if (!FWorldDelegates::OnPostWorldCleanup.IsBoundToObject(this))
42 {
44 }
45 }
46 else
47 {
49 , TEXT("Calling FManager::GetCurrent while no instance for world %s has been created, and bCreateIfMissing == false")
50 , *World.GetName());
51 }
52
53 return NewInstance;
54 }
55
56 void OnPostWorldCleanup(UWorld* World, bool /*bSessionEnded*/, bool /*bCleanupResources*/)
57 {
58 FManager** FoundInstance = WorldToInstanceMap.Find(World);
59 if (FoundInstance)
60 {
61 (*FoundInstance)->RemoveFromRoot();
63 }
64 }
65};
#define UE_DEPRECATED(Version, Message)
Definition CoreMiscDefines.h:302
#define TEXT(x)
Definition Platform.h:1272
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
#define DECLARE_LOG_CATEGORY_EXTERN(CategoryName, DefaultVerbosity, CompileTimeVerbosity)
Definition LogMacros.h:361
#define UE_LOG(CategoryName, Verbosity, Format,...)
Definition LogMacros.h:270
static UE_API FWorldCleanupEvent OnPostWorldCleanup
Definition World.h:4463
Definition UnrealString.h.inl:34
Definition World.h:918
Definition DefaultManagerInstanceTracker.h:13
FManager * GetManagerInstance(UWorld &World)
Definition DefaultManagerInstanceTracker.h:23
bool bCreateIfMissing
Definition DefaultManagerInstanceTracker.h:15
TMap< UWorld *, FManager * > WorldToInstanceMap
Definition DefaultManagerInstanceTracker.h:14
void OnPostWorldCleanup(UWorld *World, bool, bool)
Definition DefaultManagerInstanceTracker.h:56