Im implementing my own version of client prediction and server reconciliation for a custom pawn in unreal engine 5, since i couldnt use the default unreal character for my needs, as it forces you into using a capsule collision component as a root component which i dont want to use. So everything went fine up until I came across client and server state desync, which from what i understood can be caused by RTT fluctuations and/or packet loss (or maybe even frame rate drops but im not entirely sure yet). Basically the system i have now works kind of like this:
- Client has a buffer with all pending states unacked by the server
- Every tick (which isnt fixed) client locally simulates movement and sends a new state to the server
- Server receives the new state and adds it to its own unacked states buffer
- Every tick (which is fixed to say 60 TPS) server iterates through the unacked state buffer and simulates locally with the input and delta time provided in the state, it does this as many times as there are client state delta times that fit within the server time per tick (say 1 / 60 seconds), acking and removing each state from the buffer
- While acking all the moves server also checks their validity and in case of any error sends a correction RPC back to the client
- After the server is finished processing all the states in the the buffer or they reach the time per tick threshold the server sends the final state back to the client so the client can remove the already acked states in its buffer
My problem right now is finding out why exactly that happens and that when the client inevitably gets too far into the future from the server, there is no way of reliably correcting this error as the ping/framerate are always fluctuating and the client seems to always be in a desynced state.
Any ideas on what would be the best course of action in this situation?