Respawn Player after delay [C++]

Hello, I know there are tons of threads like this, but i did everything they were writing in this threads and cant do it. So what im doing: On player death im setting timer to respawn with RestartPlayer after 10 secodns. ( deathmatch) and i cant get right player to respawn. Only server is respawning himself, so i think im getting controller in bad way. I tried it all.
(Game is multiplayer)

can you show how you are triggering the respawn and which classes are involved?


void AScharacter::respawn()

APlayerController* PC = UGameplayStatics::GetPlayerController(this, 0);

UE_LOG(LogTemp, Log, TEXT("resp %A"));



ive tried changing this to getworld and millions of other combinations

Hmm i only know blueprints but i winder if your default game mode has your character class as its default pawn? if not then i think restartplayer might put tge player into a non character pawn that is more like a spectator maybe

I will check, but its interesting because i dont think default gamemode got my pawn

i Got gamemode override BP_Testgamemode and there i set default pawn. but in GamemodeBase i cant change DefaultPawn ( its gray)

Ok so i figured out i just need to get right player controller. can someone help me how to do it in multiplayer? iteration?

On every machine including the server, player controller from index 0 is usually just the furst player to be created on that selfsame machine. Player controller at index 0 of the server will not be the same player as you find at index 0 on another client machine, and on a different additional client machine, player at index 0 will be yet another different player.

Since this function you showed runs on the server and it gets player at index 0 it will always get the server’s first player and not any of the player co trollers belonging to clients who connected after the server started.

Your code is inside a CharacterPawn child class which means it inherits the vase pawn class’ function to get that pawn’s controller (i dont knkw what it is calld in C++). But it is a function the Pawns all have. In blueprint it is called just GetController I think. That returns the pawn’s controller.

So you dont need to find it you see; the pawn already holds a reference to its own controller. so just Get that and if necessary, cazt to your controller class and then call your reset player function.