Multiplayer Spawn Bug

Hello guys,
I got a weird problem, I have no idea what causes it.

Game: Multiplayer, Steam API, Blueprints Only.

Problem: Client sometimes does not spawn correctly. Means, he can´t move (essentially can´t do actions from PlayerController –> Pawn), some actions (PlayerController –> PlayerState –> Pawn) still work and input is recognized,
although it seems, that only the Multicast Events fire and only locally.Can´t see server or other clients move. Sees shooting correctly, bullets flying and hitting things, UI-Indicators still update (Are getting removed if someone gets an objective etc.). Only the movement appears to be the problem. Only error I get is a NullRef from the PawnRef getting called from an input action event in the PlayerController. No failed casts or invalid actors. Sometimes the client syncs up, sometimes he doesn´t (also quite random).
Also a weird thing, PawnRef is replicated and getting set on OwningClient aswell OnServer in the PlayerController. Now: After dying multiple times, local PawnRef has a different PawnName than the Serversided, but does not seem to be a problem, since
everything runs fine. PawnRef_NameDiff.PNG This problem occurs randomly and I couldn´t replicate it (Only by dying over and over again, amount and or cause, or time, of deaths don´t matter.)

Video Of The Problem
https://youtu.be/dJtdBV1tkvs

Tried everything I could, debugged everywhere something could go wrong, found no similar problems on google (Maybe PlayerState problem). Also disabled ragdoll, but didn´t make a difference.

Called In PlayerCharacter If A Player Dies

In Player State


Respawn In GameMode PlayerController Gets Send From The PlayerState

In PlayerState called from GameMode after spawning pawn

Respawn In PlayerController called from the PlayerState and setting the PawnRef

**
Hope you can help me, i´m quite frustrated about this problem.**

Sincerely Schmolle

When working with multiplayer, you often want to add delays to see if your problems come from replication delays. If adding delays does not fix them, it usually means you have a logic issue.

Once your problem is isolated (replication delay vs logic problem), you can work around not using delays.

I think I know what’s wrong.

You’re spawning the new character on Server and then you’re sending its direct reference to a client event “OnRespawn”. In this case, if you have a replication delay, the reference will be NULL.

Time 00 -> Server creates Character
Time 00 -> Server sends Character reference to Client (null reference since the character has not been replicated yet)
Time 01 -> Character is replicated to Client and appear at that moment (but your Event has already been fired so it’s too late!)

There are many things you can do to fix it.

Here is one solution:
Go on your Character Blueprint and search for the “OnPossessed” event. That’s an event the character receives when he gets possessed.
Create a client custom event that does everything your current “OnRespawn” client event does.
Plug it into the “OnPossessed” event (which is arriving with a server authority).

You should be fine.

To make sure I identified the problem don’t change anything to your code. First add a delay (3 seconds) after POSSESSING the character and see if you still experience your issue. If not, I think you got your problem.

Thank you,
I´ll try it as soon as I can

I tried both of your suggestions, the problem that the local playercontroller had a different name than the serverside got solved.
The main problem that the client does sometimes not spawn correctly is still there (In build and in PIE).
What seems to cause a faulty spawn is when the client goes out of “sync”, means he does not see the server move and is in a different location on the server,
but he still sees grenades and bullets flying correctly.
If the client is in that state and is killed, he will not spawn correctly. All respawn events fire and playercontroller appears to have a valid reference.

Would be grateful if you have other solutions,

Sincerely, Schmolle

Try finding what is wrong with the “bugged” player character: does he have a controller? is he properly setup? what inputs does he respond to?

Pawn can cast to playercontroller and vice versa.
He receives direct ActionInput events.
Gets casts from the PlayerState.
OnPossess and all respawn events fire.
But all events seem to only fire locally, even if they´re RunOnServer.

I can´t track down the bug, everything runs as it should.

They run locally because of “run on server IF OWNER”. you should run a server event on pawn. and from there -as you have authroity -call on player state. You do not OWN player state. the server does. so you CANT run “on server” stuff directly from client. Try it.

Works perfectly fine.

Did you really add a delay right after the “Possess” node here? Like 2 seconds? Just for the sake of debugging purpose.

i had a similar issue and fixed it with “spawn handling” -> “adjust location”. no guarantee though.

You’re not feeding the “PlayerControllerRef” parameter when spawning the Controller also. I don’t know if it can have an impact or not.

Yes, had a 3 sec delay. Also tried to set the pawn in a variable and to pass that on, same with the playercontroller. But had no effect.

It was another attempt at that problem but didn´t work out and is not used anymore.

Already set to it.

Thanks for your suggestions.

Try printing the number of player characters alive on all machines.

Is it possible that your respawn event fires several times in a row?

Nope, already checked that. Also had the ragdolls turned off, in case they were interfering with something.

Try making the character “Always Relevant” just to see if it fixes the issue.

Is already.

Ahah, you found a pretty interesting bug :smiley:

I’ll get back to it when I return from work this evening.

If I think of anything in the meantime I’ll keep you posted.

Don’t loose faith, keep it up :slight_smile:

EDIT: You did count the amount of Player Characters on the scene?

Yep, everything as it should be.

And thank you, I really appreciate your help!

So, I found an anomaly.
I debugged the remote role of the pawn.

This is if everything spawned normal:
RemoteRoles_Normal.PNG

This happens if he spawns incorrectly. The duration it stays like this, seems to be connected to when the old pawn gets destroyed (Not confirmed yet):
RemoteRoles_Anomaly.PNG

Don´t really know what it means. But I´ll do some research as soon I have time.

Try setting the owner of the spawned character right after you spawn it. (“SetOwner” to the controller you want).

Maybe just make one more try with delays by adding one in between “Spawn Actor from Class” and “Possess”.

I see we have clearly two ways of debugging and mine is far less efficient / useful in the long run. I’m debugging like the prototyper I am, adding / removing stuff that seem relevant and seeing what happens.

EDIT:
I definitely think there’s something going on with "Owner"s.

I commented the blueprints screenshots you gave us: