In Aura Project, we add the HealthBar component (Healthbar above the head) to the AuraEnemy, but I want to add it to both Enemy and Aura Characters.
So instead I have placed the component on CharacterBase (Mine is called HeroCharacterBase instead of AuraCharacterBase), and initialized it in the BeginPlay:
void AHeroCharacterBase::BeginPlay()
{
Super::BeginPlay();
UHeroUserWidget* HeroUserWidget = Cast<UHeroUserWidget>(HealthBar->GetUserWidgetObject());
if(HeroUserWidget)
{
// Sending data to health bar above character, to be seen by other players
HeroUserWidget->SetWidgetController(this);
const UHeroAttributeSet* HeroAttributesSet = Cast<UHeroAttributeSet>(AttributeSet);
if(HeroAttributesSet)
{
AbilitySystemComponent->GetGameplayAttributeValueChangeDelegate(HeroAttributesSet->GetHealthAttribute()).AddLambda(
[this](const FOnAttributeChangeData& Data)
{
OnHealthChangedDelegate.Broadcast(Data.NewValue);
});
AbilitySystemComponent->GetGameplayAttributeValueChangeDelegate(HeroAttributesSet->GetMaxHealthAttribute()).AddLambda(
[this](const FOnAttributeChangeData& Data)
{
OnMaxHealthChangedDelegate.Broadcast(Data.NewValue);
});
OnHealthChangedDelegate.Broadcast(HeroAttributesSet->GetHealth());
OnMaxHealthChangedDelegate.Broadcast(HeroAttributesSet->GetMaxHealth());
}
}
}
In the WBPHealthbar I then cast to the base character instead of Enemy, see attached image.
This works when attacking a EnemyCharacter, both Server and Client gets a updated healthbar when health changes.
But when a AuraCharacter attacks each other (both on Server and Client) their own health bar updates but it does not replicate to each other.
Any tips on how to fix this would be much appriciated, thanks in advance.