Hey there,
i know there is already a question by someone who asked why the game starts with a death animation if you dont have a resurrect transition from Dead → Alive in your Death State Machine. I ran into the same error and played around with some log messages which i would like to share.
So I narrowed down the problem that if you do not add the resurrect transition to your death state machine, the game will start and your character immediately goes into the death animation. The game however is still playable and the HUD is still displayed.
I went ahead and removed all ShooterCharacters from the game so that only the players ShooterCharacter instance is in the game. Then I added some logging messages to the ShooterCharacter::IsDead Function to see its output and what do we see? At the very beginning it returns true for a frame or two, then proceeds to return the desired starting value which is false.
Apparently this comes down to the Health and MaxHealth values being iniztialized or not. While we initialize the MaxHealth with a default value of 100.f, Health itself is uninitialized, because we set it in ShooterCharacter::BeginPlay().
If you take a look at the images you can see in the logs that it will initialize the floats with 0 or in some cases dont print the float value at all when facing an uninitialized variable. Well if health is 0 then the ShooterCharacter::IsDead() function of course will return true. This means that the State machine will request the ShooterCharacter::IsDead() function before the ShooterCharacter::BeginPlay() has run entirely and this returns faulty values.
I managed to get around this issue by initializing the Health value in the header file with a value greater than 0, in this case I simply set it to MaxHealth.
So now to my questions, because I actually have two questions:
- Can someone reproduce this bug?
- Is there a better workaround if so? I dont really like setting values in headerfiles and I am curious
Thanks for your help!