So I have a user widget c++ class called “HealthBar3”, and a BP user widget class called “HealthBar3BP” that is based off of the c++ class. The BP widget simply has a canvas panel with a progress bar in it, both of which are bound to the c++ class by UPROPERTY(meta = (BindWidget))
variables in the “HealthBar3.h” file:
UPROPERTY(meta = (BindWidget))
UProgressBar* healthPercentBar;
UPROPERTY(meta = (BindWidget))
UCanvasPanel* baseCanvas;
Now in my scene I have a character called “badguy2” who has a widget component, the widget class is set to a new created widget in “badguy2.cpp” to of the class HealthBar3BP:
hWidget = CreateDefaultSubobject<UWidgetComponent>("HealthWidget");
hWidget->SetWidget(CreateWidget<UUserWidget>(GetWorld(), hBar));
Where hBar is UPROPERTY(EditAnywhere) TSubclassOf<UUserWidget> hBar;
This works fine.
When I spawn multiple of these “badguy2” characters they all have the HealthBar3BP widget, however, in “badguy2.cpp” I set the percent of the progress bar to be the health of “this” badguy2 character:
Cast<UHealthBar3>(hWidget->GetWidget())->SetHealthPercent(this->health / 100.0f);
in “HealthBar3.cpp” this does:
void UHealthBar3::SetHealthPercent(float percent) {
healthPercentBar->SetPercent(percent);
}
}
but all of the health bars have the same percent. So it works but they all seem to have the same progress bar.
I know exactly what is happening I just don’t know how to fix it. Basically every badguy2 has the HealthBar3BP widget, but for some reason there is only one instance of that widget shared across all badguy2s.
So my question is how do I get each spawned badguy2 to have its own instance of “HealthBar3BP”?