Hello,
I recently renamed one of my Components in my BaseCharacter class from “HealthComp” to “HealthComponent”, and this rename seems to have broken the component in some ways. It seems that the component is constructed from the base class (BaseCharacter) rather than the instance of each actor. For example, this log
if (GetHealthComponent()) UE_LOG(LogTemp, Warning, TEXT("%s's Health component is owned by %s (Should be %s)"), *GetActorLabel(), *GetHealthComponent()->GetOwner()->GetActorLabel(), *GetActorLabel());
results in the following output for my characters. If you notice, BP_FirstPersonCharacter0’s is not what it should be.
LogTemp: Warning: BP_GruntMedium0's Health component is owned by BP_GruntMedium0 (Should be BP_GruntMedium0)
LogTemp: Warning: BP_GruntMedium1's Health component is owned by BP_GruntMedium1 (Should be BP_GruntMedium1)
LogTemp: Warning: BP_GruntMedium2's Health component is owned by BP_GruntMedium2 (Should be BP_GruntMedium2)
LogTemp: Warning: BP_Grunt's Health component is owned by BP_Grunt (Should be BP_Grunt)
LogTemp: Warning: BP_FirstPersonCharacter0's Health component is owned by BaseCharacter (Should be BP_FirstPersonCharacter0)
I don’t know exactly why, but it was broken for several classes earlier, but now it just remains for the player character BP. The code change I think that produced this bug was this
HealthComponent = CreateDefaultSubobject<UHealthComponent>(TEXT("HealthComp"));
HealthComponent = CreateDefaultSubobject<UHealthComponent>(TEXT("HealthComponent"));
The way to resolve this seems to be to recreate BP_FirstPersonCharacter0 which was a pain…