Character Selection

Hey
i’m working on a multiplayer game, and after you pick a server there’s an option to choose between blue and red,
my question is how do I make it so that whenever I press the button of the red team it will spawn in the red spawn, and vice versa.

But, that’s not so easy to answer mate. This is a bigger setup you need, but i can give you little bit of input.

In the time you should gather some screenshots of your current setup and tell us how good you are with blueprints.

To spawn a Character and Possess it, you need to let the Server to this in Multiplayer. The Client is not allowed to do this.
This is important to know, since you are using UMG for the Selection and a HUD is placed ClientSide.

So the spawning code/nodes, needs to be placed in an Actor where you can call a “RunOnServer” Event on. A RunOnServer Event
will be dropped if you are not the NetOwner of the Actor you are calling it on. A good place for these functions are the PlayerController
class. You are the NetOwner of this AND the Possess function is located here.

So you may want to create 2 CustomEvents in your PlayerController that are set to “RunOnServer”. One for Blue and one for Red.
In your UMG Widget, you may have 2 Buttons, one for Blue and again, one for Red. When you press one of them, you use
“GetPlayerController”, cast it to your custom PlayerController Class and call the matching CustomEvent you created.

This custom Event should Spawn your Character Actor of choice and Possess it! This only needs to be done on the ServerSide. The Client
will be able to control the Character after that. (The Server Symbol at the Possess Node will tell you about that).

And you also want to place the logic about selecting a specific SpawnPoint here.
Let’s say you have 2 different SpawnPoint actors, once again one for Blue and one for Red.

I would create 2 Arrays in my GameMode (NODE: GameMode only exists on the Server, but since we only need the SpawnPoints on the Server
this is working). One for all the Red and one for all the Blue Spawnpoints.
On the “BeginPlay” of the GameMode, you call “GetAllActorsOfClass” 2 times, again for Red and Blue, and fill the Arrays with the result.

Now, in your PlayerController, where you have the 2 Events, you can use “GetGameMode” and Cast it to your Custom GameMode class to access the
SpawnPoints. Since we are working on the ServerSide with these Events, you can get the GameMode. On ClientSide it would return NULL.

From here on you can get a random SpawnPoint from the Array or how ever you want to decide how to spawn.