Does the Server tell the client to spawn?

Hey guys, read some information on the AGameMode You can read here

Assuming everything went well, AGameMode::PostLogin is called.
At this point, it is safe for the server to start calling RPC functions on this PlayerController.

So I have also looked the Shooter Game example GameMode and I’ve very confused to how the Server Spawns the incoming connection.

void AMyServerGameMode::PostLogin(APlayerController *NewPlayer)
{
	GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Black, FString(TEXT("Got player")));

	Super::PostLogin(NewPlayer);
	AMyPlayerController* NewPC = Cast<AMyPlayerController>(NewPlayer);

}

So I tested this, and on my dedicated server, I do get two “Got Player”. As the server I have that client (who joined) I have their Player Controller.

Now do I tell the player controller (Server calls to owning client) that “Hey spawn a pawn in this location…”. Or as the server, do I spawn a pawn first, then tell the player controller to posses it?

So this is kind of a guess just based off of how other spawned actors work.

The server definitely spawns the player’s pawn on itself in RestartPlayer on the GameMode with SpawnDefaultPawnFor. I think, if it uses similar stuff to how other replicated actors work, the server adds it to the networked actors list, which then gets replicated down to the clients, and then the clients will spawn it for themselves locally and then initialize it with the data from the server, which I’d imagine would include the possessing controller.

That’s an educated guess, but I’m not very certain about it at all because there’s a lot of special player spawning functions to do with spawning client players, but I can’t tell if they’re just to spawn players in specific situations other than arbitrarily for all cases.

If you want to check for yourself put some breakpoints in your constructors/postinitializecomponents/Possessedby functions on your player class and launch your game with the debugger attached to the client.

I liked the comment, thumbs up. Would have reply soon, but Anime.

So, from your comment, the server spawns the actor/pawn (which is replicated) meaning that clients will spawn a dummy actor/pawn in parallel with the servers.

So as you said, if the server has the players controller from post login, the server will use that controller to posses the pawn, which means the client will do the same thing, theoretically.

Cheers, time to implement this :smiley: