Rollback Network Model
In the traditional Unreal network model you have two main tools to process functionality and store state; RPCs and replicated variables. A replicated variable is just a variable that is marked for replication which is then distributed to other objects when it changes and an RPC is a simple message to tell other objects to run a function. Due to how our computers are connected, this message could take anywhere between 10ms to 500ms or upwards. To get around this limit, we often try to predict functionality on the client so that the game experience is still smooth. The issue with RPCs and replicated variables is that the receiver executes all of this information out of order so what they are seeing is a mix of mismatched data from the server over the last X seconds. This also means logic is not predictable or reliable and applying prediction techniques is often not possible as the target object may be in a different place in the world on the server compared to the local players object.
The rollback network model was created to avoid these flaws and allow prediction at a very core level. All state is stored for each frame so that every client can simulate the exact same experience. Each world ticks at a predictable rate every frame to ensure the frame length matches and that logic is always executed at the correct time. A client can apply changes locally to the world state but each frame state will be compared to the authoritative server state when received. If this state differs in any way, the client will roll back to the authoritative state and then reapply all local changes to that state again to catch up to the current predicted time.
There are also other benefits that come with this:
- Enhanced security as you can now shift more logic onto the server knowing that you can reproduce it faithfully on your local machine.
- Much more fair in competitive settings as there is greater control over how data is displayed and also ensures that players see the full world state at the same time.
This model does however come with its own difficulties:
- All logic must be deterministic to prevent regular resimulations when checking against the authoritative state.
- Resimulations can be computationally expensive due to executing logic for that one frame over and over again so it is important to keep visual-only logic split from the network tick.
- To ensure that all packets for a frame have been received and in order, packets must be executed after a small buffer of time. This makes it hard to work between standard RPCs/variables and state in the network model.
Unreal provides the Network Prediction Plugin to give us this rollback network functionality. Any system using the NPP should work out of the box with other systems that have also implemented it. The plugin is still fairly new and has a few places where it can be improved but it’s being actively worked on and is very capable as it is.
For more information on the Network Prediction Plugin and how to use and extend it, feel free to visit the tutorial on my personal blog.