Hello,
I’m pretty new to C++ and Game Development, been at it for 4 months now, and am trying to build a component based Action RPG. Currently, I have my Health, Stamina, and Mana set up and are regenerating appropriately, however, the issue comes when I change state (using and Enum) from OutofCombat to InCombat. When this change happens, it resets my current Attributes back to where they started at the beginning of play.
Here are my variables:
public:
UPROPERTY(BlueprintReadWrite, EditDefaultsOnly, Category = “Character Attributes”)
float Health = 50.f;
private:
UPROPERTY(EditDefaultsOnly, Category = “Character Attributes”)
float MaxHealth = 300.f;
UPROPERTY(EditDefaultsOnly, Category = "Character Attributes")
float HealthRegenRate = .001f;
UPROPERTY(EditDefaultsOnly, Category = "Character Attributes")
float CombatHealthRegenRate = .0005f;
Here is what the regeneration Code looks like:
void UCombat_Component::RegenHealth() // This is the same code as for Mana and Stamina, just replace the word health with Mana and Stamina on each variable
{
if (Health < MaxHealth) { Health = Health + HealthRegenRate; }
if (Health > MaxHealth) { Health = MaxHealth; }
if (CombatStatus == ECombatStatus::OutofCombat) { HealthRegenRate = .001f; }
else if (CombatStatus == ECombatStatus::InCombat) { HealthRegenRate = CombatHealthRegenRate; }
}
and here is what my Enum update method looks like:
void UCombat_Component::UpdateCombatStatus()
{
if (LastTimeAttacked > 5 && LastTimetoAttack > 5)
{
CombatStatus = ECombatStatus::OutofCombat;
}
else
{
CombatStatus = ECombatStatus::InCombat;
}
}
I would appreciate any help on figuring out why it is resetting and how to fix it.