From a00ea8073adc020a319b82f5fbf8c4436e4d9a32 Mon Sep 17 00:00:00 2001
From: David Gilbert <gilbert@vr.rwth-aachen.de>
Date: Mon, 19 May 2025 19:27:22 +0200
Subject: [PATCH] fix(interaction): also removes delegate from ActionBehaviour
 on EndPlay

---
 .../Private/Interaction/Interactables/ActionBehaviour.cpp   | 6 ++++++
 .../Private/Interaction/Interactables/GrabBehavior.cpp      | 3 +--
 .../Public/Interaction/Interactables/ActionBehaviour.h      | 1 +
 3 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/Source/RWTHVRToolkit/Private/Interaction/Interactables/ActionBehaviour.cpp b/Source/RWTHVRToolkit/Private/Interaction/Interactables/ActionBehaviour.cpp
index ff1d0272..f6e2eae4 100644
--- a/Source/RWTHVRToolkit/Private/Interaction/Interactables/ActionBehaviour.cpp
+++ b/Source/RWTHVRToolkit/Private/Interaction/Interactables/ActionBehaviour.cpp
@@ -17,3 +17,9 @@ void UActionBehaviour::BeginPlay()
 
 	OnActionEventEvent.AddDynamic(this, &UActionBehaviour::OnActionEvent);
 }
+void UActionBehaviour::EndPlay(const EEndPlayReason::Type EndPlayReason)
+{
+	OnActionEventEvent.RemoveDynamic(this, &UActionBehaviour::OnActionEvent);
+
+	Super::EndPlay(EndPlayReason);
+}
diff --git a/Source/RWTHVRToolkit/Private/Interaction/Interactables/GrabBehavior.cpp b/Source/RWTHVRToolkit/Private/Interaction/Interactables/GrabBehavior.cpp
index c62cfb45..a9fc2c3d 100644
--- a/Source/RWTHVRToolkit/Private/Interaction/Interactables/GrabBehavior.cpp
+++ b/Source/RWTHVRToolkit/Private/Interaction/Interactables/GrabBehavior.cpp
@@ -18,9 +18,8 @@ UGrabBehavior::UGrabBehavior()
 
 void UGrabBehavior::BeginPlay()
 {
-	Super::BeginPlay();
-
 	OnActionReplicationStartedOriginatorEvent.AddDynamic(this, &UGrabBehavior::ReplicationOriginaterClientCallback);
+	Super::BeginPlay();
 }
 
 void UGrabBehavior::EndPlay(const EEndPlayReason::Type EndPlayReason)
diff --git a/Source/RWTHVRToolkit/Public/Interaction/Interactables/ActionBehaviour.h b/Source/RWTHVRToolkit/Public/Interaction/Interactables/ActionBehaviour.h
index bf3afea3..2a65a20f 100644
--- a/Source/RWTHVRToolkit/Public/Interaction/Interactables/ActionBehaviour.h
+++ b/Source/RWTHVRToolkit/Public/Interaction/Interactables/ActionBehaviour.h
@@ -42,4 +42,5 @@ protected:
 							   const FInputActionValue& Value);
 
 	virtual void BeginPlay() override;
+	virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override;
 };
-- 
GitLab