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.
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).
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.
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
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.
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.