# Whether the event stays bound?

**URL:** <https://forums.unrealengine.com/t/whether-the-event-stays-bound/1913207>\
**Category:** C++\
**Tags:** event-dispatcher, unreal-engine, question\
**Created:** [June 23, 2024, 12:39am UTC](https://forums.unrealengine.com/t/whether-the-event-stays-bound/1913207 "2024-06-23T00:39:20Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![blAddddDe](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@blAddddDe](https://forums.unrealengine.com/u/blAddddDe)\
**Post date:** [June 23, 2024, 12:39am UTC](https://forums.unrealengine.com/t/whether-the-event-stays-bound/1913207/1 "2024-06-23T00:39:21Z")

</div>

Hi all, I’m wondering if I need `OnNotificationStopDisplay.RemoveDynamic(...)` or or it will remove the binding itself. Here’s the Code:

```c++
void UHUDWidgetBase::TryToInvokeNotification()
{
	if(CurrentNotification) return;
	if(WidgetQueue.Num() == 0) return;
	
	CurrentNotification = WidgetQueue[0];
	CurrentNotification->NotificationDisplay();
	WidgetQueue.RemoveAt(0);

	CurrentNotification->OnNotificationStopDisplay.AddDynamic(this, &UHUDWidgetBase::TryToInvokeNotification);
	CurrentNotification = nullptr;
}

```

I’m confused at this point:

```auto
CurrentNotification->OnNotificationStopDisplay.AddDynamic(this, &UHUDWidgetBase::TryToInvokeNotification);
	CurrentNotification = nullptr;

```

Please Help 🙏

---

<div class="post-metadata">

**Author:** ![rokenrock](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rokenrock/32/1040844_2.png) [@rokenrock](https://forums.unrealengine.com/u/rokenrock)\
**Post date:** [June 23, 2024, 2:16am UTC](https://forums.unrealengine.com/t/whether-the-event-stays-bound/1913207/2 "2024-06-23T02:16:27Z")

</div>

Yes, you will need to remove the OnNotificationStopDisplay binding, assuming it’s possible for the notifications to ever call that multiple times.

It may be best to add a dedicated callback function that OnNotificationStopDisplay binds to instead of just binding directly to TryToInvokeNotification. For that dedicated callback function, the notification could pass a reference to self. There you could remove the binding and then call TryToInvokeNotification().

That’s the type of reason largely every unreal C++ delegate passes a reference to self.

---

<div class="post-metadata">

**Author:** ![blAddddDe](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@blAddddDe](https://forums.unrealengine.com/u/blAddddDe)\
**Post date:** [June 23, 2024, 7:33pm UTC](https://forums.unrealengine.com/t/whether-the-event-stays-bound/1913207/3 "2024-06-23T19:33:53Z")

</div>

Thank you for your answer and explanation.  
My immediate thought was that it couldn’t just become unlinked, so I reworked the function a bit:

```c++
void UHUDWidgetBase::TryToInvokeNotification()
{
	if(CurrentNotification)
	{
		CurrentNotification->OnNotificationStopDisplay.RemoveDynamic(this, &UHUDWidgetBase::TryToInvokeNotification);
		CurrentNotification = nullptr;
	}

	if(WidgetQueue.Num() == 0) return;

	CurrentNotification = WidgetQueue[0];
	CurrentNotification->NotificationDisplay();
	WidgetQueue.RemoveAt(0);

	CurrentNotification->OnNotificationStopDisplay.AddDynamic(this, &UHUDWidgetBase::TryToInvokeNotification);
}

```

---

<div class="post-metadata">

**Author:** ![system](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/1/3/713c9d3f58553f0de89543d76a8a3a2779dc9fa4.png) [@system](https://forums.unrealengine.com/u/system)\
**Post date:** [July 23, 2024, 7:34pm UTC](https://forums.unrealengine.com/t/whether-the-event-stays-bound/1913207/4 "2024-07-23T19:34:04Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
