Hello, I have a dilemma with delegate handling. I have a Storage Widget with a button to upgrade the capacity of Storage State. After releasing the button, I would like to display an upgrade popup. In my case the Storage State class is responsible for that. And now I found two different solutions to accomplish this task. The first one is a classic approach to delegates which looks like this:
void UStorageWidget::CreateUpgradeButtonBinding()
{
if (UpgradeButton)
{
UpgradeButton->OnReleased.AddDynamic(this, &UStorageWidget::InitializeStorageUpgrade);
}
}
void UStorageWidget::InitializeStorageUpgrade()
{
if (StorageState)
{
StorageState->CreateUpgradePopup();
}
}
The second way is based on a direct delegation to Storage State:
void UStorageWidget::CreateUpgradeButtonBinding()
{
if (UpgradeButton && StorageState)
{
UpgradeButton->OnReleased.AddDynamic(StorageState, &AStorageState::CreateUpgradePopup);
}
}
I have never seen anyone do it the second way, so I would like to ask you which solution is better and why. Is the second approach even reasonable?