When I kill an enemy my game crashes. It happens only when the bot dies a moment before he wants to shoot. I can kill him(them), when he walks after me, when he makes the first shot, but as he is a moment before shooting and he dies the game crashes.
Line ShooterCharacter.cpp: 55 was
UE_LOG(LogTemp, Warning, TEXT(“The %s has %f health left”), *GetOwner() → GetName(), Health);
I put if(GetOwner()) above and it works just fine.
I wonder if there any other way to output objects name and health left?
No. GetOwner gets the owning actor for the component or actor. For a component that would be the actor it is attached to, for an actor it’s whatever you set it to it would be nullptr if you don’t.
AShooterCharacter
|- MeshComponent
|- MyComponent
|- etc.
If you log GetName() in MyComponent then that would print “MyComponent” along with it’s ID. If you were to do GetOwner()->GetName() that would print the name of the character it’s attached to.