Losing life

How do you make sure your player keeps losing lives

Have a re spawn that i copied form the unreal documentation but i want to make my player lose a life. The variable is in my player bp. i set up a custom event in game mode where it will minus one life when respawn but it only does it once never again

The problem is that each time your character dies you are destroying it and spawning a new character with new variables. And that is why this is not working.

You can do one of the following:

  • Instead of destroying the actor and spawning another one, just change it’s location to the spawn location, and reset the variables you need to manually
  • Store the number of life in an external blueprint like your player controller, or your game state

How would you do the game state?

Just use your player controller, a game state is more useful for multiplayer games

I just add it to begin play i am guessing or a new function?

Player controller is an actual blueprint that you create, and specify it in the game mode

so it isnt like the third person bp that i have been storing everything in

you would store stuff in your third person blueprint, but since you are destroying it each time your actor dies, all the information saved in it are lost and resseted when you spawn a new one. That is why this operation should be done in an external file that is running during the game all the time, like the player controller.

Then i add the to the gamemode as a different function?

You create a player controller if you don’t already have one, and assign it in the game mode default properties, then you create a variable in the player controller called life count, and then from your thirdpersonBP you can “getPlayerController”>“Cast to the Player controller you created”, access the life count variable

So i am guessing that will be like a branch function to be called when player is dead then lose a life or is it a different event?

I think so

Awesome it worked thank you