Unity Netcode 100% Server Authoritative with Client Prediction and Reconciliation

preview_player
Показать описание
Synchronizing Rigidbodies in Unity Netcode for GameObjects is NOT EASY - BUT we are going to get into it. This video is Part 1/2 about handling prediction, reconciliation, and other techniques related to lag and cheating in multiplayer games! It's also the first video in the Kart series where we add additional REAL players to the project with Netcode for GameObjects!

Next week we will continue with the same topic of Client Prediction and Reconciliation and include some Extrapolation.

#unity3d #gamedev #indiedev

▬ Contents of this video ▬▬▬▬▬▬▬▬▬▬

0:00 Intro
0:40 Netcode for GameObjects
7:30 How and Why
9:15 NetworkTimer
10:20 Circular Buffer
11:20 Handling Input and State
16:50 Demo
18:30 Reconciliation
22:40 Testing

*KART Models used in this video*

*Follow me!*
Рекомендации по теме
Комментарии
Автор

Hi everyone! This particular topic will span 2 videos, so if you have any comments or questions, I may be able to address them in Part 2! Don't forget to click the LIKE button when you find something useful in the video!

git-amend
Автор

I'm now right before doing reconciliation in the video but I tested my game and it is weird. All clients connected to the server/host have the same move speed but the host for some reason is faster than everybody else... In server mode, everybody is perfectly at the same speed. Any idea why?

GaLzZy.
Автор

The UI buttons added through your package don't seem to do anything when pressed, any idea why that could be?

EDIT: Nevermind! It was because i didn't have an EventSystem anywhere

rr_gaming
Автор

I'm having a weird problem where the host kart that first joins is working fine, but any karts that join afterwards are having their Rigidbody's isKinematic setting enabled. I can fix this by just making sure to check its off once i call handleMovement, but I'm wondering if you would have an idea why this is happening, and how I can prevent it from spawning each kart this way? I've also tried setting the kinematic property to false in the awake method and spawn method, but i always have to fallback to the handleMovement method to fix it.

Jecyn
Автор

@git-amend I don't understand something about the logic in the ReconcileState function. Within the while loop, physics isn't actually happening right? So adding force and adding torque each tick within the loop doesnt actually achieve movement tick by tick does it?

mauricedib
Автор

I'm using this for a space ship controller. It always has a forwad movement vector and rotates based on the player's input. I'm facing a lot of stutter rotating left/right because of it being in FixedUpdate, rather than Update itself. Could I duplicate the HandleClient and HandleServer Tick into Update on top of having it in FixedUpdate? That feels like the wrong approach.

Does anyone have any ideas?

danielweber
Автор

Man I have watched this video 4 or 5 times now.... thanks for putting this out there, your content is invaluable

anthonygiannotti
Автор

Hi, can you please explain how does the client prediction works on host? As host is the server and the client at the same time, so when we run handleServerTick it is simulating the tick that was already simulated by the same entity. I got this problem when I was implementing client prediction in my game and my control system does work not on host because of this.

КондрачукЯрославВолодимирович
Автор

Thanks SO much for sharing your knowledge! I wanna ask an off top question: how did you manage to pull "Create field" and "Create Unity serialized field" higher in the Rider Context Action menu? I couldn't find any information about it. May be you should consider to create a video about Rider tricks that you use?

metsker
Автор

I followed this video and the client moves way slower than the server. Why is that?

manuelcosta
Автор

Hey man! Amazing video. I was able to follow it without any errors about a month back but now I have come back in need of help lmao. Is there anyway make an object teleport, such as when respawning the player? Whenever I try to modify the players position with ServerRPC's the server reconciliation kicks in and recalls me back to its expected position. Thank you!

trix_dev
Автор

Hey, I've implemented this with unity's relay system and the clients' movement is always correct, but the hosts movement does not get transmitted to the clients and just ends up standing there. Any idea why this might be happening?

shiiroitori
Автор

Also, what is preventing a cheater from preventing the call of handleServerReconciliation() ?, doesn't that need to be run on the server?

HalfBlind
Автор

Also, for me if I use a dedicated server, which i will, if on my client I raise the moveSpeed, it still syncs with the server and no reconciliation happens for some reason... I'm not sure where this is from... Even after following the entire video and code, it's like it is still the client who dictates the movement

GaLzZy.
Автор

Many thanks for this tutorial. Great work!
But I'm having some trouble. In my game, the host is always moving approx. twice as fast as the clients, while the clients move at the correct speed. Any Idea what I could have done wrong?
I used 90% of your code and I'm not using rigidbodies, instead I use a character controller. Not calling ProcessMovement in HandleServerTick gives me normal host movement but of course no client movement at all.
I also had to comment out the SwitchAuthorityMode method. I get really strange and jaggy behaviour for the client with this.

wabugi
Автор

Hi

How to change host ownership without disconnecting players in netcode and relay
In this case when host player disconnect i want to change host owner without make all players rejoin

Please help

AmAs
Автор

Great tutorials! However, I'm a bit confused about this one thing. If you have a client network transform constantly updating it's position on the server, does that mean that when we check for differences between the client and server we are only checking for differences that occur on a one tick timeframe? Because in my mind, after that one tick, the client position, even if incorrect, would become the server position due to the Client network transform. Thanks again for the tutorial.

HalfBlind
Автор

I just tested something and this is not really server authoritative because whenever i cheat values on the client, the server just accepts them for some reason... I'm not sure where i'm doing it wrong to be honest

GaLzZy.
Автор

If only Nintendo understood this code lol

FrankTinsley
Автор

This has been an invaluable resource for getting my head around how to implement this. I have successfully used this to implement a variation of the whole concept in a very different game within Godot. Thank you for sharing.

JoeFroShow