multiplayer: Client player spawn without controller ( empty controller )

I’m trying to get players to spawn from the right controllers, they even go to the right place but players that are clients spawn without controller

in the first image is the initial logic in the game mode of the game after the fast travel map, it will pick up the spawn player on the map and then it will check which team the player selected

second image: on the controller of the player who entered the map it takes the information of which team the player chose in his gameinstance and returns the information to the server

third image: the player’s controller returns this function to the server to spawn the player in the right place

From the print strings it looks like the right team for the player, it spawns on the map but the player doesn’t have ownership of the character, don’t move or anything

Do you know what the problem is or a better way to do this?

GameMode classes only exist on the server so you can’t make any RPC’s or replicate any variables in this class.

The “CheckSpawn” RunOnOwner RPC actually just runs immediately on the server that called it.

When you “SpawnCharacter” the “NewPlayer” variable is quite important as it is the player that is going to Possess the character. Where is that being set?


it is defined at the beginning of the postlogin

if i can’t publish anything in game mode, then how can i get which team each client chose? remembering that the variable is in the gameinstance of each client!

A PlayerController is Replicated to the owner. Each player owns the PlayerController given on Login.

So you can make a RunOnServer event on the PlayerController with the team ID chosen.
Then when server-side the server can make a normal function call to the GameMode class with the PlayerController the call came from as a parameter.

You don’t need to add PlayerControllers to an Array OnPostLogin then.

something like that ?

Game Mode :

PlayerController :

No.

When you are connected to a server then ALL gamemode events happen on the Server. The clients have no gamemode at all at this point.

OnPostLogin happens on the server so it makes no sense to call SpawnTeamClient from the Server to the Server (RunOnServer RPC).

What you should do is on the PlayerController make a Server RPC on input when the client selects a team ID. Then you get to the server-side on the PlayerController where can call the GameMode and give it the PlayerController as a parameter.

You should read up on how Replication and Ownership works in Unreal Engine and it will make a lot more sense.
Be cautious about learning from the first result on YouTube, unfortunately there is a lot of confusion and bad practices floating out there.

this is how when the player chooses a team in the widget

If GI is GameInstance then this also won’t work. The GameInstance is just an Object and it can’t be replicated.

Just focus on using the PlayerController for RPC’s. Where you get or send the ID doesn’t really matter as long as the RPC’s only exist on the PlayerController or something else that can replicate.

I changed the team choice event to be stored in the controller

I don’t know if this is a problem but the lobby menu is a map and the game map and another one, but they use the same controller, when the play host a travelmap happens and I’m pulling the players in postlogin