Hi,
I’ve got a problem with the values being returned for a super class.
I’ve got the following classes:
- CharacterBase → inherits from ACharacter
- HeroCharacter → inherits from CharacterBase.
- EnemyCharacter → inherits from CharacterBase.
I’ve got a variable bDied in the CharacterBase class which is set to true if health drops below 0.0f
if (Health <= 0.0f && !bDied) {
bDied = true;
GetMovementComponent()->StopMovementImmediately();
GetCapsuleComponent()->SetCollisionEnabled(ECollisionEnabled::NoCollision);
UE_LOG(LogTemp, Warning, TEXT("Has the Character Died: %s"), (bDied?TEXT("True"):TEXT("False")))
}
This method only exists in the CharacterBase class.
Within the animation blueprint, which is the same for all enemy and the game character, I would cast the owner pawn to the CharacterBase and get the value of bDied so that I can play the Death animation.
The value returned is always false!!!
If I base the enemy off CharacterBase class, then bDied is returned true and the animation plays!!
Looks like some inheritance and casting thing, although not sure if this is C++ thing or UE thing, so not sure how’d I google for this. Would really like to know what’s going on here.
Thanks,