diff --git a/Source/UniversalLogging/Private/UniversalLogging.cpp b/Source/UniversalLogging/Private/UniversalLogging.cpp index 641e190493d076cda1299fbce851fcdbc10def6c..3fce5e3c4036a310b0dc7f2c25dd2a30b1b860cf 100644 --- a/Source/UniversalLogging/Private/UniversalLogging.cpp +++ b/Source/UniversalLogging/Private/UniversalLogging.cpp @@ -20,13 +20,14 @@ void UniversalLoggingImpl::StartupModule() FWorldDelegates::OnPostWorldInitialization.AddRaw(this, &UniversalLoggingImpl::OnWorldStart); FWorldDelegates::OnWorldPostActorTick.AddRaw(this, &UniversalLoggingImpl::OnPostActorTick); + FWorldDelegates::OnWorldCleanup.AddRaw(this, &UniversalLoggingImpl::OnWorldEnd); #if WITH_EDITOR - FEditorDelegates::BeginPIE.AddRaw(this, &UniversalLoggingImpl::OnSessionStart); - FEditorDelegates::EndPIE.AddRaw(this, &UniversalLoggingImpl::OnSessionEnd); + FEditorDelegates::BeginPIE.AddRaw(this, &UniversalLoggingImpl::OnSessionStart); + FEditorDelegates::EndPIE.AddRaw(this, &UniversalLoggingImpl::OnSessionEnd); #endif - Session_ID = ""; + Session_ID = ""; } void UniversalLoggingImpl::ShutdownModule() @@ -41,10 +42,10 @@ void UniversalLoggingImpl::OnWorldStart(UWorld* World, const UWorld::Initializat On_Screen_Log_Actor = dynamic_cast<AOnScreenLog*>(World->SpawnActor(AOnScreenLog::StaticClass())); //only set Session_ID on the first world of this session - if(Session_ID != "") - return; + if(Session_ID != "") + return; - if (World->IsPlayInEditor()) + if (World->IsPlayInEditor()) ResetSessionId("PlayInEditor"); else if (World->IsPlayInPreview()) ResetSessionId("PlayInPreview"); @@ -52,6 +53,11 @@ void UniversalLoggingImpl::OnWorldStart(UWorld* World, const UWorld::Initializat ResetSessionId("Play"); } +void UniversalLoggingImpl::OnWorldEnd(UWorld*, bool bSessionEnded, bool bCleanupResources) +{ + On_Screen_Log_Actor = nullptr; +} + void UniversalLoggingImpl::OnSessionStart(const bool) { Session_ID = ""; diff --git a/Source/UniversalLogging/Private/UniversalLogging.h b/Source/UniversalLogging/Private/UniversalLogging.h index 1f0c4bd59d71151a7e7ae4a7628c5295f3061e77..d6a98cc1fc847640b53d2d6f1966f26c5ccb9291 100644 --- a/Source/UniversalLogging/Private/UniversalLogging.h +++ b/Source/UniversalLogging/Private/UniversalLogging.h @@ -15,7 +15,8 @@ public: void ShutdownModule() override; void OnWorldStart(UWorld*, const UWorld::InitializationValues); - void OnSessionStart(const bool); + void OnWorldEnd(UWorld*, bool bSessionEnded, bool bCleanupResources); + void OnSessionStart(const bool); void OnSessionEnd(const bool); void OnPostActorTick(UWorld*, ELevelTick, float);