I am having hard time undestranding the OnRep_ServerState

Hi!

This is very great tutorial and very important one! So I have been trying to get grasp of everything before moving to next lecture. This one is giving me a headache.

So I think I undestand everything to the point where server changes the ServerState variable. So when server changed the variable, OnRep function is run on clients, right? What I don’t undestrand is why we ain’t experiencing the glitch?

The function starts with:

SetActorTransform(ServerState.Transform);

Doesn’t that mean that we would first experience the glitch jump when we set the position where the server tells us? Why we run this function first?

Next we are are setting velocity that is all good.

Velocity = ServerState.Velocity;

Next. we are are running the

ClearAcknowledgedMoves(ServerState.LastMove);

What exactly is happening here? The function says that if our move timestamp is bigger than the server one we create a new array of that. I still don’t undestrand what kind of moves are in the new Array, could you give more clarification about that? After we have created new array, we foreach that new array and run SimulateMove for each array index. I don’t undestrand how we get the effect we have by doing that (removing the glitching)?

That bring me back to first question: Why we are doing this in beginning?

SetActorTransform(ServerState.Transform);

Thanks!

No, because we haven’t rendered yet. Remember, everything that happens in your code is single threaded and happens before rendering.

By creating a new array we are effectively removing all the moves that we (the client) know the server has already applied.

1 Like

So we get a new ServerState, which to the clients seems like it’s from the past. Snapping back to this ‘past point in time’ causes glitching. So instead of only snapping back, we snap back and then replay all the moves we remember doing since that past point in time.

If there are no disagreements between the client and server (other than just timing), replaying all our moves since that point in time should give us the exact same end result as what we had been calculating one tick at a time before the update. Same result = no glitching = win.

For this to work, we must only replay moves we did after that point in time, not before. That’s what ClearAcknowledgedMoves() is doing. We know that any move with a timestamp less than the ServerState.LastMove’s timestamp is already factored into the ServerState.Transform/Velocity, so this method is just removing those older “stale” moves from our list.

We need the SetActorTransform(ServerState.Transform) because that’s the starting point we’re replaying our moves from. It already has most of our past moves factoed into it we just need to add on the moves that the server didn’t know about yet.

2 Likes

Privacy & Terms