Skip to content

Commit f15a572

Browse files
authored
Merge pull request #23 from Tinadim/cleaning-up-listeners-on-pie-session
Cleaning up listeners on PIE session
2 parents f9e5cd8 + 75bf3ce commit f15a572

File tree

5 files changed

+36
-5
lines changed

5 files changed

+36
-5
lines changed

Source/GlobalEventSystem/GlobalEventSystem.Build.cs

+5
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,10 @@ public GlobalEventSystem(ReadOnlyTargetRules Target) : base(Target)
5050
// ... add any modules that your module loads dynamically here ...
5151
}
5252
);
53+
54+
if (Target.Type == TargetRules.TargetType.Editor)
55+
{
56+
PublicDependencyModuleNames.Add("UnrealEd");
57+
}
5358
}
5459
}

Source/GlobalEventSystem/Private/GESHandler.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44

55
TSharedPtr<FGESHandler> FGESHandler::PrivateDefaultHandler = MakeShareable(new FGESHandler());
66

7+
void FGESHandler::Clear()
8+
{
9+
PrivateDefaultHandler = MakeShareable(new FGESHandler());
10+
}
11+
712
bool FGESHandler::FirstParamIsCppType(UFunction* Function, const FString& TypeString)
813
{
914
TArray<FProperty*> Properties;

Source/GlobalEventSystem/Private/GlobalEventSystem.cpp

+15-5
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,29 @@
22

33
#include "GlobalEventSystem.h"
44

5+
#if WITH_EDITOR
6+
#include "Editor.h"
7+
#include "GESHandler.h"
8+
#endif
9+
510
#define LOCTEXT_NAMESPACE "FGlobalEventSystemModule"
611

712
void FGlobalEventSystemModule::StartupModule()
813
{
9-
// This code will execute after your module is loaded into memory; the exact timing is specified in the .uplugin file per-module
10-
14+
#if WITH_EDITOR
15+
EndPieDelegate = FEditorDelegates::BeginPIE.AddLambda([](bool boolSent)
16+
{
17+
UE_LOG(LogTemp, Warning, TEXT("Clearing FGESHandler"));
18+
FGESHandler::Clear();
19+
});
20+
#endif
1121
}
1222

1323
void FGlobalEventSystemModule::ShutdownModule()
1424
{
15-
// This function may be called during shutdown to clean up your module. For modules that support dynamic reloading,
16-
// we call this function before unloading the module.
17-
25+
#if WITH_EDITOR
26+
FEditorDelegates::EndPIE.Remove(EndPieDelegate);
27+
#endif
1828
}
1929

2030
#undef LOCTEXT_NAMESPACE

Source/GlobalEventSystem/Public/GESHandler.h

+5
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ class GLOBALEVENTSYSTEM_API FGESHandler
2525
//Get the Global (default) handler to call all other functions
2626
static TSharedPtr<FGESHandler> DefaultHandler();
2727

28+
/**
29+
* Clear all listeners and reset state
30+
*/
31+
static void Clear();
32+
2833
/**
2934
* Create an event in TargetDomain.TargetFunction. Does nothing if already existing.
3035
*/

Source/GlobalEventSystem/Public/GlobalEventSystem.h

+6
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,10 @@ class FGlobalEventSystemModule : public IModuleInterface
1111
/** IModuleInterface implementation */
1212
virtual void StartupModule() override;
1313
virtual void ShutdownModule() override;
14+
15+
private:
16+
17+
#if WITH_EDITOR
18+
FDelegateHandle EndPieDelegate;
19+
#endif
1420
};

0 commit comments

Comments
 (0)