Hooking up with the new reliable KCP

I’ll keep this post short and sweet because if I don’t it will be silly deep. But we made the choice to use a low latency network stack called KCP. Recently it’s been gaining traction in the multiplayer game realm for its performance. And games like Genshin Impact have proved it is ready to go mainstream.

Most of the time data can be handled unreliable, especially things like transform data that get updated like mad. Missing a packet in these scenarios is minimal thanks to some design tricks we employ. But sometimes they need to be reliable and we need to guarantee they reach the designated targets. This is where KCP comes into play.

KCP handles missed packets much better than TCP, as seen by these benchmarks. So we decided to use two KCP “channels” per client, one for building data and one for everything else reliable. This along with utilizing unreliable UDP allows for three different ways for data to move around, preventing any kind of log jam that might happen. Check this page from improbable.io if you want more details, it was the source for most of this post.

Mirror gets to work with KCP

I was very excited when I noticed the main Mirror team started to check out KCP. This would provided some low hanging optimizations compared to existing TCP transports like batching messages and better handling of dropped packets. If we try to send more than 1200 bytes, our default MTU, fragmentation will take care of us. And also the cutting edge MirrorNG is implementing KCP better then baseline Mirror, exposing all its glory to the user.

We still need to do concrete testing, but so far performance and latency have been wonderful at quick glance with the KCP integration. It’s been exciting times all around with networking. We added snapshot interpolation and there are new announcements on the general Unity Networking front. Unity picked up MLAPI and Photon is talking about a revolutionary network stack called Fusion. Sage Towers netcode future is extremely secure!

Leave a Reply