How do i spawn character on server?

I have a class inheriting from character and a controller. In the controller i want to spawn the character. It has to be replicated on all clients. Which steps, in code, do i need for this? i can’t get it to work for myself… .
I tried many things but i can’t get the pawn to show on other clients. There aren’t a lot of clear explanations about this stuff.
I’ll show you what i have tried so far.
In the controller’s header i have:

UFUNCTION(Server, Reliable, WithValidation)
	void serverSpawnPawn();
	void serverSpawnPawn_Implementation();
	bool serverSpawnPawn_Validate();

Inside the begin play function of the controller i call this

if (Role == ROLE_Authority)
		GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Yellow, FString::Printf(TEXT("server")));

And for the serverSpawnPawn i have this:

void AFlappyBirdController::serverSpawnPawn_Implementation()
	FActorSpawnParameters spawnParams;
	APlayerCharacter* pawn = GetWorld()->SpawnActor<APlayerCharacter>(pawnTypes[mode], FVector(0, 0, 0), FRotator(0, 0, 0), spawnParams);
	owningPawn = pawn;
bool AFlappyBirdController::serverSpawnPawn_Validate()
	return true;

Then my pawn is inheriting from ACharacter.
I ticked every checkbox in my controller and pawn that says something about should replicate and things like that so i don’t know why they are not on all clients. It’s only visible on it"s own screen.

Hi, you should download the content examples project form the Epic Games launcher.

Head over to the Blueprint Networking chapter and go through the explanations they provide you!

Here is the documentation for said chapter:

Ohh, I now noticed that this is posted in the C++ section…

Well, to start off, asking for a complete guide on how to get character replication working is kind of pointless. There are guides already on this: A new, community-hosted Unreal Engine Wiki - Announcements - Unreal Engine Forums

You need to point to a more specific problem if you want help!


You should post what you have tried and why it doesn’t work. You would need to create a server function to serve this purpose or just work off of existing functions such as BeginPlay. (ran on client and server). Just make sure you check if you have authority if you are going to spawn through begin play.

But to make your own function.

UFUNCTION(Server, Reliable, WithValidation)

void SpawnCharacter_Implementation()
//spawn function
//APawn* SpawnedPawn = GetWorld()->SpawnActor(pawnclass, transform,spawn info);

bool SpawnCharacter_Validate()
return true;

if this still doesn’t work, check if your pawn is replicated.
On a side note, you should check out some of the free resources available made by Epic such as ShooterGame. It will teach you the basics.

I added the things i have tried :slight_smile: