Download

Trying To Restart Level Upon Players Death

Hello,

I’ve setup a simple split-screen game where you kill other players. I’m trying to figure out how to restart the level once all but one player is alive. I’m currently able to restart the level if there is just 2 players in the game. When there are more than two players I can’t get the level to restart.

On begin play I’m casting to the game mode and am getting the number of players. I then set that number to a variable.
I’m having players die from radial damage so when a player gets hit by radial damage I’m calling this function to decrease the number or players by 1 and to restart the level if the number of players reaches a certain number.

I’m doing all of this in the player blueprint.

Any ideas on what I’m doing wrong?

daef10f46537c3fe971f47aa9edcb1abbb7d529b.png
811a991e7c82d26829b3f697ded681fc1867ef90.png

Where are you doing this?
Have you tried setting a break piont when there are only two players left to debug?

I would suggest tracking this in the game instance or game mode via a (set of) functions.
That way the server can call the restart level (IIRC there is a console command called “restartlevel” to restart the current level).

HTH

I’m doing this in the player blueprint.

I’m not sure how to setup a break point. I’ll have to read up on those.
I used the event tick and added a print string with the number of players variable. It appears that the variable keeps resetting itself after it gets decremented. Like if a have 3 players in the game and one player dies/is destroyed it shows the number of players goes down to 2 then it goes right back to 3 players.

Is this a networked game?
If so: You will need to do a authority check and only modifer gameplay related stuff on the server.

You can set a breakpoint by pressing F9 on the BP node, But reading up on debugging will help in the long term.

I recomment doing this in the game mode blueprint.
Rough overview:

  • Create a function to decrement the number of alive players
  • Set the function to run on the server(There should be a doc/wiki page about doing this in BP, I can only recall how to do this in C++)
  • Check if there is one or less players alive
  • If true: Restart level
  • Rinse and repeat :slight_smile:

HTH

Currently it’s not a networked game but I would like to add that functionality eventually.
I was finally able to figure out a way to get this working. I imagine I’ll have to change it once I start implementing network play. My issue was that the number of players wasn’t staying decreased once someone died. I was able to fix this by create a simple function in the player blueprint. After the player dies it decrements the number of players and then I’m having it cast to game mode and resetting the number of player variable.

This is working how I want it to, but I’m sure I’ll have to change it for network play :smiley:

Untitled3.png

I would change this into a function on the game mode, And then Just do a authority check when it is called.
That should be all that is needed to get this to work for networked enabled version.

HTH
Good luck!

Ok cool, that sounds easy enough! I’ll try to do that once I start implementing network play. If I run into issues I know who to ask :smiley:

Thank you!!

If you haven’t yet, check out my Network Compendium: http://cedric.bnslv.de/unreal-engine-4-network-compendium-released/

Also, I would suggest you either start with Multiplayer or you totally focus on Singleplayer first.

Adding it in later is nearly never an option, as it requires you to rewrite the Game. Network needs a lot more code and also
different solutions for things that were straight forward in Singleplayer.

This is a good read!
BTW: Thanks eXi!

Oh wow, this is pretty awesome! I’ll have to read through this along with going through your learning projects.
Thank you for this!!

I’ll shift my focus to getting multiplayer setup before I add anymore things to my game.