Unreal crashes when I win

Hello, people.

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.

This is my log:

"Unhandled Exception: EXCEPTION_ACCESS_VIOLATION reading address 0x0000000000000018

UE4Editor_SimpleShooter_2194!AShooterCharacter::TakeDamage() [N:\Unreal Projects\SimpleShooter\Source\SimpleShooter\ShooterCharacter.cpp:55]
UE4Editor_SimpleShooter_2194!AGun::PullTrigger() [N:\Unreal Projects\SimpleShooter\Source\SimpleShooter\Gun.cpp:52]"

l fixed the bug:

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?

That’s printing the owner’s name not the actor’s name.

UE_LOG(LogTemp, Warning, TEXT(“The %s has %f health left”), *GetName(), Health);

Would be printing the actor’s name.

So I don’t need to call GetOwner()? A thought it is the only way to call GetName ().

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.

Yep, I get it!)
Thank you very much)

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.