I’m “cross-posting” this from AnswerHub, in hopes that more experienced people view and can help me solve this issue:
https://answers.unrealengine.com/que…mplementa.html
Hello,
I’m having trouble hooking up a Multicast Delegate to a BlueprintImplementableEvent function, for a simple health/armor display. I’m doing it in C++ for maintainability purposes
Here’s the code I have:
On my character header:
DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FOnHealthChanged, float, Health, float, Armor);
UPROPERTY(BlueprintAssignable)
FOnHealthChanged OnHealthChanged;
(I’m not sure if BlueprintAssignable is needed there, since I"m trying to assign it using C++, even though it will execute blueprint code. Left it in anyway. Advice is welcome )
At the end of my TakeDamage function, on my character:
OnHealthChanged.Broadcast(Health, Armor);
And on my custom UUserWidget, I declare on my header:
UFUNCTION(BlueprintImplementableEvent)
void HealthChanged(float Health, float Armor);
And on CPP:
bool UHavenBaseHealthArmorWidget::Initialize() {
bool Success = Super::Initialize();
if (!Success) return false;
// There are sanity checks in here, making sure all pointers are fine.
MyCharacter->OnHealthChanged.AddDynamic(this, &UBaseHealthArmorWidget::HealthChanged);
return true;
}
But when I damage myself, nothing happens. If I set a breakpoint tin the blueprint, it seems it’s not executed. If I set a breakpoint on my character TakeDamage function, the function is being called.
I’m not sure what I"m missing there to make it work. Any idea of what’s wrong and how I should fix it?
Thank you very much in advance!