[Basic guide] How to select a Player Start in multiplayer

I’m inexperienced with UE4, but I wanted to help any other newbies by presenting a basic solution to this problem which took me a while to solve.
So, you want a simple multiplayer game, but the players seem to be spawning at random Player Starts. This means that half the time some of your players are not spawning! Here’s how to fix it:

Open your game mode. Hover your cursor over the plus sign next to ‘Functions’ on the left, select ‘Override’ and then click ‘Choose Player Start’.
Now, you can add logic to select an unused Player Start. You can create an array of actors and set it to the Player Starts array when BeginPlay is called in the Event Graph, like so:

Then, you can go back to your ChoosePlayerStart function and get the first item, setting it as the currently chosen Player Start as an actor variable and removing it from the array, so that it won’t be chosen again.

Of course, it would be easy to use a random number for the index when getting a Player Start from the array:

Now that you have the basic logic for a working system, you can improve upon it and adjust it to your needs. I hope this helps somebody :slight_smile:
Edit: this works fine when testing with a dedicated server. However, switching to a listen server seems to cause an issue that I haven’t managed to fix.

In C++, you can override the ChoosePlayerStart function with this:

Header
virtual AActor* ChoosePlayerStart_Implementation(AController* Player) override;

And then define the function so that it returns an AActor* in the .cpp file.

8 Likes

Thanks for this! I’m fairly experienced with blueprint but somehow never thought of doing this.

OMG This is so helpful! Thx for sharing!

Really nice, thank you, Cabbage.

Just a hint for anybody who is interested: It seems that BeginPlay is not guaranteed to run before ChoosePlayerStart, is it? (I tested with UE 4.18.) So maybe you have to set the variable PlayerStarts within ChoosePlayerStart and ensure the assignment is only done once by an additional bool variable.

3 Likes

That is true. I am trying to run a dedicated server and Choose Player Start gets called before BeginPlay

1 Like


Thank you for this, just the solution I was looking for. I made some slight tweaks just to keep all the code in the same area to control when it was run, I think will solve the issues described by phisigma and mcleary.
I just added a branch to check if the “Get all player starts” part of the code had been run before. This was to make sure that the array wasn’t refilled with the previously deleted player start.

Hope that this helps someone and that I don’t break any forum rules by replying to a 4 year old thread!

4 Likes

For anyone that’s using a listen server, you have to Set the Player Starts in the Construction Script instead of Begin Play, because the server will pick a Player Start before BeginPlay is called due to the server being added before the clients. Hope this helps :smiley:

5 Likes

Thank you all a lot for this :slight_smile:
Saved me

the problem Im having is on a dedicated server, when the map restarts, pawns get placed on any player starts, how can we make it so it places it on the correct team if its set as an integer in the player start BP?

what if I have 3 teams , will the code be the same? Or do I need to tell it what team is which?