Clients spectating instead of playing (replication issues?)
I made some slight changes to my game, that should in no way influence the spectating state: I created a new c++ class based on HUD, which just adds a Widget to the PlayerScreen on BeginPlay. I selected that HUD class as my default HUD class in my BP_Gamemode and I modified my BirdsEyePawn, so it does not create a Widget anymore.
After I made the changes, when I play in editor with a dedicated server, the client does not spawn the default pawn anymore and spawns the SpectatorPawn instead. When playing with a listen server and a client, the listen server still spawns the default pawn.
These are the relevant logs, when I get the SpecatorPawn instead of my DefaultPawn (BP_BirdsEyePawn):
The SpawnActor failure seems to be the PlayerCameraManager, because I do not have a PlayerCameraManager Class assigned in my BP_PlayerController, and that Log dissappears, when I assign a PlayerCameraManager class. Weirdly, when I go back to the previous version in Git, the PlayerCameraManager Class is still unassigned, but the SpawnActor failure does not seem to appear.
The other message missing from the logs, when I play with the previous version is that the SpectatorPawn_0 was spawned. So maybe the match state is not correctly replicated to the client?
I am really at a loss about what is going on. Any help or things I could try would be very much appreciated.
If someone from Epic chimes in, I would happily send you a download link to my project. I would prefer to send the download link to an email address or through some other medium, where I don't have to share the link with the whole internet.
asked Oct 28 '16 at 09:25 AM in C++ Programming
I was able to find out what caused the change in behaviour. By adding the following functions back into my BirdsEyePawn, I was able to recreate the previous behaviour:
That made me realize, what might actually be happening: My replicated function call inside ABirdsEyePawn::PossessedBy is delaying the APlayerController::ClientRestart() call just long enough, that the Client already has destroyed the placeholder PlayerController, which then receives the ClientRestart() call, resulting in the Client's PlayerController performing a false Restart and acting as if it possessed my BirdsEyePawn for a couple of seconds, until the BirdsEyePawn is garbage collected.
So my actual problem is something else and I will probably create a new answerhub post, once I figured that out, because no one wants to read through all my crap.
Or at least I wouldn't want to read through all of that :)
EDIT: Nevermind, I found the solution. A while ago I overrode APawn::IsNetRelevantFor() like so:
That of course resulted in the Pawn being deleted on the owning client, which in turn resulted in the above dilemma.
Follow this question
Once you sign in you will be able to subscribe for any updates here