{"id":521,"date":"2022-01-12T23:10:35","date_gmt":"2022-01-12T22:10:35","guid":{"rendered":"https:\/\/www.bellingo.de\/blog\/?p=521"},"modified":"2023-05-12T17:51:25","modified_gmt":"2023-05-12T15:51:25","slug":"devblog-avoiding-unity-netcode","status":"publish","type":"post","link":"https:\/\/www.bellingo.de\/blog\/devblog-avoiding-unity-netcode\/","title":{"rendered":"DevBlog: Avoiding Unity Netcode"},"content":{"rendered":"\n<p>When I started <a href=\"https:\/\/www.bellingo.de\/blog\/devblog-the-idea-behind-network-traders\/\" target=\"_blank\" rel=\"noreferrer noopener\">Network Traders<\/a> a year ago, I was intrigued by Unity&#8217;s new <a href=\"https:\/\/docs-multiplayer.unity3d.com\/\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">networking layer<\/a>, which was then still the <a href=\"https:\/\/forum.unity.com\/threads\/the-open-source-mlapi-project-joins-the-unity-family.1016209\/\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">MLAPI<\/a>. After some testing, I realised that it was just not the right tool for my application. So when does it make sense to use Netcode and what might be an alternative for your project if it doesn&#8217;t?<\/p>\n\n\n\n<!--more-->\n\n\n\n<p>Unity has already made several attempts at providing its own network package. The last one, <a href=\"https:\/\/docs.unity3d.com\/Manual\/UNet.html\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">UNet<\/a>, came with its own <a href=\"https:\/\/www.bellingo.de\/blog\/category\/game-development\/unity-en\/unet-en\/\" target=\"_blank\" rel=\"noreferrer noopener\">set of snags<\/a>, and was deprecated a while ago. It has been replaced by Netcode <a href=\"https:\/\/forum.unity.com\/threads\/the-open-source-mlapi-project-joins-the-unity-family.1016209\/\" target=\"_blank\" rel=\"noreferrer noopener\">in late 2020<\/a>, which is a continuation of the third-party library MLAPI. <\/p>\n\n\n\n<div class='code-block code-block-2' style='margin: 8px 0; clear: both;'>\n<script async src=\"https:\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js?client=ca-pub-5801154588989661\"\n     crossorigin=\"anonymous\"><\/script>\n<!-- Posts Standard -->\n<ins class=\"adsbygoogle\"\n     style=\"display:block\"\n     data-ad-client=\"ca-pub-5801154588989661\"\n     data-ad-slot=\"5874520813\"\n     data-ad-format=\"auto\"\n     data-full-width-responsive=\"true\"><\/ins>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script><\/div>\n\n\n\n\n<p>But Unity always had a very specific application in mind, which is to support devs at making real-time multiplayer games. It offers features like synchronising game objects, authoritative server architecture, and prediction. For performance reasons, it is based on UDP rather than TCP.<\/p>\n\n\n\n<p>I needed none of these features for Network Traders. The original idea was to connect devices directly and exchange specific packages of data. This does not require syncing objects, as they do not coexist on both devices, nor does it need an authoritative server, or movement prediction. Even UDP is rather a hindrance, as there is time in abundance but data loss is critical. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Low-Level Netcode Alternatives<\/h2>\n\n\n\n<p>Therefore, I soon stopped trying to bend Netcode to my needs. It provides lots of high-level features, but I was looking for a low-level networking library. Interestingly, Netcode does not care about which networking library it uses, so there is a whole list of <a href=\"https:\/\/github.com\/Unity-Technologies\/multiplayer-community-contributions\" target=\"_blank\" rel=\"noreferrer noopener\">alternative transport protocols<\/a>. From these, I chose to try <a href=\"https:\/\/forum.unity.com\/threads\/ruffles-another-reliable-udp-library.678343\/\" target=\"_blank\" rel=\"noreferrer noopener\">Ruffles<\/a>, which was the original transport layer of MLAPI. It is a UDP protocol, so, as I said above, not really what I needed. But it was well suited for broadcasting in a local network in order to identify other devices. So I stuck with it for a while.<\/p>\n\n\n\n<p>However, for exchanging data I wanted a more reliably and easy-to-use TCP protocol. <a href=\"https:\/\/mirror-networking.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">Mirror Networking<\/a> is another high-level API supporting different transport layers. One of them is <a href=\"https:\/\/github.com\/vis2k\/Telepathy\" target=\"_blank\" rel=\"noreferrer noopener\">Telepathy<\/a>, the original Mirror transport, made for Unity using TCP. It was what I was looking for, although I fell into one trap I would like to warn you about.<\/p>\n\n\n\n<p>Mirror provides an authoritative server which defines what state of the clients is correct. When a client disconnects, the server is not really interested in the client&#8217;s state anymore, and any message still in the queue may be lost. In case of a peer-to-peer connection where every message is important this is disastrous. If you think about using Telepathy in that way, check out my more detailed explanation <a href=\"https:\/\/github.com\/vis2k\/Telepathy\/issues\/108\" target=\"_blank\" rel=\"noreferrer noopener\">here<\/a> and follow the link to my fix on GitHub.<\/p>\n\n\n\n<p>Finally, I also had to connect the client with my data server, which is not a Unity application. So I began with an implementation of asynchronous server sockets based on the example code by <a href=\"https:\/\/aaronluna.dev\/blog\/csharp-tpl-socket-methods\/\" target=\"_blank\" rel=\"noreferrer noopener\">Aaron Luna<\/a>. If you now think, &#8222;why would he use three different networking implementations?&#8220;, you are perfectly right to wonder. In the end, I dumped it to just use Telepathy on the server as well.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How about you?<\/h2>\n\n\n\n<p>In the case of networking, Unity itself provides few alternatives if you do not need exactly what Netcode is meant for, because you just happen to <em>not <\/em>write an online first-person shooter. What networking layers are you using, and what are your experiences? Did you try Unity&#8217;s new Netcode? I would be happy if you left a comment below.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>When I started Network Traders a year ago, I was intrigued by Unity&#8217;s new networking layer, which was then still the MLAPI. After some testing, I realised that it was just not the right tool for my application. So when does it make sense to use Netcode and what might be an alternative for your &hellip; <a href=\"https:\/\/www.bellingo.de\/blog\/devblog-avoiding-unity-netcode\/\" class=\"more-link\"><span class=\"screen-reader-text\">DevBlog: Avoiding Unity Netcode<\/span> weiterlesen<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[229,49,94,55],"tags":[230,237,231,239,238,138,67],"class_list":["post-521","post","type-post","status-publish","format-standard","hentry","category-devblog","category-game-development","category-online-games","category-unity-en","tag-devblog","tag-netcode","tag-network-traders","tag-ruffles","tag-telepathy","tag-unet","tag-unity-en"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.8 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>DevBlog: Avoiding Unity Netcode - Games:Tech:Blog<\/title>\n<meta name=\"description\" content=\"Unity&#039;s new Netcode networking API is a mighty tool for real-time multiplayer online games, but it may not work as well for other genres.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.bellingo.de\/blog\/devblog-avoiding-unity-netcode\/\" \/>\n<meta property=\"og:locale\" content=\"de_DE\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"DevBlog: Avoiding Unity Netcode - Games:Tech:Blog\" \/>\n<meta property=\"og:description\" content=\"Unity&#039;s new Netcode networking API is a mighty tool for real-time multiplayer online games, but it may not work as well for other genres.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.bellingo.de\/blog\/devblog-avoiding-unity-netcode\/\" \/>\n<meta property=\"og:site_name\" content=\"Games:Tech:Blog\" \/>\n<meta property=\"article:published_time\" content=\"2022-01-12T22:10:35+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-05-12T15:51:25+00:00\" \/>\n<meta name=\"author\" content=\"Ingo\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Verfasst von\" \/>\n\t<meta name=\"twitter:data1\" content=\"Ingo\" \/>\n\t<meta name=\"twitter:label2\" content=\"Gesch\u00e4tzte Lesezeit\" \/>\n\t<meta name=\"twitter:data2\" content=\"4\u00a0Minuten\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.bellingo.de\/blog\/devblog-avoiding-unity-netcode\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.bellingo.de\/blog\/devblog-avoiding-unity-netcode\/\"},\"author\":{\"name\":\"Ingo\",\"@id\":\"https:\/\/www.bellingo.de\/blog\/#\/schema\/person\/82498f8ac21d11f5948cab6d0a9807e9\"},\"headline\":\"DevBlog: Avoiding Unity Netcode\",\"datePublished\":\"2022-01-12T22:10:35+00:00\",\"dateModified\":\"2023-05-12T15:51:25+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.bellingo.de\/blog\/devblog-avoiding-unity-netcode\/\"},\"wordCount\":589,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.bellingo.de\/blog\/#\/schema\/person\/82498f8ac21d11f5948cab6d0a9807e9\"},\"keywords\":[\"DevBlog\",\"Netcode\",\"Network Traders\",\"Ruffles\",\"Telepathy\",\"UNet\",\"Unity\"],\"articleSection\":[\"DevBlog\",\"Game development\",\"Online Games\",\"Unity\"],\"inLanguage\":\"de\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.bellingo.de\/blog\/devblog-avoiding-unity-netcode\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.bellingo.de\/blog\/devblog-avoiding-unity-netcode\/\",\"url\":\"https:\/\/www.bellingo.de\/blog\/devblog-avoiding-unity-netcode\/\",\"name\":\"DevBlog: Avoiding Unity Netcode - Games:Tech:Blog\",\"isPartOf\":{\"@id\":\"https:\/\/www.bellingo.de\/blog\/#website\"},\"datePublished\":\"2022-01-12T22:10:35+00:00\",\"dateModified\":\"2023-05-12T15:51:25+00:00\",\"description\":\"Unity's new Netcode networking API is a mighty tool for real-time multiplayer online games, but it may not work as well for other genres.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.bellingo.de\/blog\/devblog-avoiding-unity-netcode\/#breadcrumb\"},\"inLanguage\":\"de\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.bellingo.de\/blog\/devblog-avoiding-unity-netcode\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.bellingo.de\/blog\/devblog-avoiding-unity-netcode\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.bellingo.de\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"DevBlog: Avoiding Unity Netcode\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.bellingo.de\/blog\/#website\",\"url\":\"https:\/\/www.bellingo.de\/blog\/\",\"name\":\"Games:Tech:Blog\",\"description\":\"A Blog about Games, Technology in Games, and Technology in General\",\"publisher\":{\"@id\":\"https:\/\/www.bellingo.de\/blog\/#\/schema\/person\/82498f8ac21d11f5948cab6d0a9807e9\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.bellingo.de\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"de\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/www.bellingo.de\/blog\/#\/schema\/person\/82498f8ac21d11f5948cab6d0a9807e9\",\"name\":\"Ingo\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"de\",\"@id\":\"https:\/\/www.bellingo.de\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/93a4b9881ee1983f4fafc7e996ce82a42c3a1540c18f7417809c08a19658f167?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/93a4b9881ee1983f4fafc7e996ce82a42c3a1540c18f7417809c08a19658f167?s=96&d=mm&r=g\",\"caption\":\"Ingo\"},\"logo\":{\"@id\":\"https:\/\/www.bellingo.de\/blog\/#\/schema\/person\/image\/\"},\"url\":\"https:\/\/www.bellingo.de\/blog\/author\/ingo\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"DevBlog: Avoiding Unity Netcode - Games:Tech:Blog","description":"Unity's new Netcode networking API is a mighty tool for real-time multiplayer online games, but it may not work as well for other genres.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.bellingo.de\/blog\/devblog-avoiding-unity-netcode\/","og_locale":"de_DE","og_type":"article","og_title":"DevBlog: Avoiding Unity Netcode - Games:Tech:Blog","og_description":"Unity's new Netcode networking API is a mighty tool for real-time multiplayer online games, but it may not work as well for other genres.","og_url":"https:\/\/www.bellingo.de\/blog\/devblog-avoiding-unity-netcode\/","og_site_name":"Games:Tech:Blog","article_published_time":"2022-01-12T22:10:35+00:00","article_modified_time":"2023-05-12T15:51:25+00:00","author":"Ingo","twitter_card":"summary_large_image","twitter_misc":{"Verfasst von":"Ingo","Gesch\u00e4tzte Lesezeit":"4\u00a0Minuten"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.bellingo.de\/blog\/devblog-avoiding-unity-netcode\/#article","isPartOf":{"@id":"https:\/\/www.bellingo.de\/blog\/devblog-avoiding-unity-netcode\/"},"author":{"name":"Ingo","@id":"https:\/\/www.bellingo.de\/blog\/#\/schema\/person\/82498f8ac21d11f5948cab6d0a9807e9"},"headline":"DevBlog: Avoiding Unity Netcode","datePublished":"2022-01-12T22:10:35+00:00","dateModified":"2023-05-12T15:51:25+00:00","mainEntityOfPage":{"@id":"https:\/\/www.bellingo.de\/blog\/devblog-avoiding-unity-netcode\/"},"wordCount":589,"commentCount":0,"publisher":{"@id":"https:\/\/www.bellingo.de\/blog\/#\/schema\/person\/82498f8ac21d11f5948cab6d0a9807e9"},"keywords":["DevBlog","Netcode","Network Traders","Ruffles","Telepathy","UNet","Unity"],"articleSection":["DevBlog","Game development","Online Games","Unity"],"inLanguage":"de","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.bellingo.de\/blog\/devblog-avoiding-unity-netcode\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.bellingo.de\/blog\/devblog-avoiding-unity-netcode\/","url":"https:\/\/www.bellingo.de\/blog\/devblog-avoiding-unity-netcode\/","name":"DevBlog: Avoiding Unity Netcode - Games:Tech:Blog","isPartOf":{"@id":"https:\/\/www.bellingo.de\/blog\/#website"},"datePublished":"2022-01-12T22:10:35+00:00","dateModified":"2023-05-12T15:51:25+00:00","description":"Unity's new Netcode networking API is a mighty tool for real-time multiplayer online games, but it may not work as well for other genres.","breadcrumb":{"@id":"https:\/\/www.bellingo.de\/blog\/devblog-avoiding-unity-netcode\/#breadcrumb"},"inLanguage":"de","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.bellingo.de\/blog\/devblog-avoiding-unity-netcode\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.bellingo.de\/blog\/devblog-avoiding-unity-netcode\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.bellingo.de\/blog\/"},{"@type":"ListItem","position":2,"name":"DevBlog: Avoiding Unity Netcode"}]},{"@type":"WebSite","@id":"https:\/\/www.bellingo.de\/blog\/#website","url":"https:\/\/www.bellingo.de\/blog\/","name":"Games:Tech:Blog","description":"A Blog about Games, Technology in Games, and Technology in General","publisher":{"@id":"https:\/\/www.bellingo.de\/blog\/#\/schema\/person\/82498f8ac21d11f5948cab6d0a9807e9"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.bellingo.de\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"de"},{"@type":["Person","Organization"],"@id":"https:\/\/www.bellingo.de\/blog\/#\/schema\/person\/82498f8ac21d11f5948cab6d0a9807e9","name":"Ingo","image":{"@type":"ImageObject","inLanguage":"de","@id":"https:\/\/www.bellingo.de\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/93a4b9881ee1983f4fafc7e996ce82a42c3a1540c18f7417809c08a19658f167?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/93a4b9881ee1983f4fafc7e996ce82a42c3a1540c18f7417809c08a19658f167?s=96&d=mm&r=g","caption":"Ingo"},"logo":{"@id":"https:\/\/www.bellingo.de\/blog\/#\/schema\/person\/image\/"},"url":"https:\/\/www.bellingo.de\/blog\/author\/ingo\/"}]}},"_links":{"self":[{"href":"https:\/\/www.bellingo.de\/blog\/wp-json\/wp\/v2\/posts\/521","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.bellingo.de\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bellingo.de\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bellingo.de\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bellingo.de\/blog\/wp-json\/wp\/v2\/comments?post=521"}],"version-history":[{"count":7,"href":"https:\/\/www.bellingo.de\/blog\/wp-json\/wp\/v2\/posts\/521\/revisions"}],"predecessor-version":[{"id":985,"href":"https:\/\/www.bellingo.de\/blog\/wp-json\/wp\/v2\/posts\/521\/revisions\/985"}],"wp:attachment":[{"href":"https:\/\/www.bellingo.de\/blog\/wp-json\/wp\/v2\/media?parent=521"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bellingo.de\/blog\/wp-json\/wp\/v2\/categories?post=521"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bellingo.de\/blog\/wp-json\/wp\/v2\/tags?post=521"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}