Download

Element will not remove from array

Hi I’m making simple multiplayer BR type game where for testing, there are 3 players in the arena and last player left wins. Everything seems to be working great except for the code determining which place you get. The following code is in my gamemode blueprint.

The Player Died event is called from the character blueprint and passed with the player controller. What this is supposed to do, is set the placement to how many people are left alive, and then remove the player controller from the list of who is left alive.

I’ve used print statements and determined that it is not properly removing the elements from the array. If there are 3 players in the game, it works for the first player to die and removes the player from the array. But it will not remove any more regardless if the other players die.

I printed the Display Name for each element in the array and it shows:

Cube_PC2 Cube_PC1 Cube_PC Players alive: 3

After the first player dies, it then shows:

Cube_PC2 Cube_PC1 Players alive: 2

After, this it will not change these values so when the next player dies:

Cube_PC2 Cube_PC1 Players alive: 2

Any thoughts on why this would be? Thank you for any help!

(1) The event isn’t replicated, and (2) the “SwitchAuthority” node only allows the host to run the code. This will only make it work for one player: the host.

Make the event “Run On Server”, change the input from player controller to playerstate (because player controllers aren’t replicated), and remove the switch authority node because the event will run on the server.

The last problem I see is that the active player list appears to be stored in the player controller/character (whichever one you have this code in). That will cause each player to have their own copy of the list, so when you remove one, it won’t propagate to the other players. You should only store it in one shared place, like the gamestate. Make sure it’s replicated and only modify it on the server; if you modify it on the client, it won’t replicate.