Object is bound to delegate, before binding is executed in code.

Hi. I’ve created a class deriving from UHorizontalBox, it is a custom class that helps with gamepad navigation. I have a strange problem with delegate binding. In the OnWidgetRebuilt function, I’m binding functions to delegates in HorizontalBox’s children - which are custom buttons(OnHover, OnClick, etc.). The problem is that before the OnWidgetRebuilt function is executed there is already appropriate function bound to that delegate(don’t know why) and sometimes even there are bindings that don’t exist in code anymore. For example, when I created binding to OnUnhovered and later on decided to remove it, it is still somehow bound to that function. I have tried executing this code not only in OnWidgetRebuilt, but also RebuildWidget and PostLoad, with no results, rebuilding project doesn’t help either.

I’ve tried to debug it with breakpoints and RebuildWidget happens only once, I even protected it with a bool check just to be sure. The only thing that helped was to clear binding list from that delegate and then bind my functions to it, but that doesn’t solve my problem because then I can’t bind anything to buttons in my widget’s construct function. On top of that there is a huge freeze in-game when any widget with my custom class is shown, during the freeze it gives my this error message:

error points to line 60 in db_interactivehorizontalbox.cpp :

Btn->OnButtonClicked.AddDynamic(this, &UDB_InteractiveHorizontalBox::SelectButtonByRef);

It didn’t freeze and it didn’t give me an error when whole binding logic was in PostLoad, but problems with binding existed anyway.

whole function:

void UDB_InteractiveHorizontalBox::OnWidgetRebuilt()
{
	Super::OnWidgetRebuilt();

	if (bInitOnStart && !bInit && !IsDesignTime())
	{
		bInit = true;

		for (int i = 0; i < GetChildrenCount(); i++)
		{
			auto* Btn = GetButtonAtIndex(i);
			if (Btn)
			{
				Btn->SetPanelButton(true);
				if (PanelWidgetType == EDB_PanelWidgetType::SelectOnHover)
				{
					Btn->OnButtonHovered.AddDynamic(this, &UDB_InteractiveHorizontalBox::SelectButtonByRef);
				}
				else if (PanelWidgetType != EDB_PanelWidgetType::MultiSelect && PanelWidgetType != EDB_PanelWidgetType::LockOnSelect)
				{
					Btn->OnButtonHovered.AddDynamic(this, &UDB_InteractiveHorizontalBox::HighlightButtonByRef);
				}
				Btn->OnButtonClicked.AddDynamic(this, &UDB_InteractiveHorizontalBox::SelectButtonByRef);
			}
		}
		if (PanelWidgetType == EDB_PanelWidgetType::Standard || PanelWidgetType == EDB_PanelWidgetType::SelectOnHover)
			SelectButtonByIndex(SelectedButtonOnStart);
	}
}

Because all the functions that I mentioned are happening not only in game time, but also design time, is it possible that these delegates start with something bound to them?

I’m probably missing something obvious, but I don’t know how to move on, as I’ve been trying to solve that for hours. If anyone could help, I would be very glad.

Did you ever figure out what it was? I have similar issue and cannot figure it out