{"id":31979,"date":"2024-11-01T09:04:38","date_gmt":"2024-11-01T09:04:38","guid":{"rendered":"http:\/\/atmokpo.com\/w\/?p=31979"},"modified":"2024-11-01T11:33:51","modified_gmt":"2024-11-01T11:33:51","slug":"unity-basics-course-network-connection-status","status":"publish","type":"post","link":"https:\/\/atmokpo.com\/w\/31979\/","title":{"rendered":"Unity Basics Course: Network Connection Status"},"content":{"rendered":"<p><body><\/p>\n<p>In game development, network connections are essential for creating multiplayer games that allow multiple players to participate simultaneously. This tutorial will explain in detail how to set up network connections in Unity and monitor connection status. This article is aimed at beginner developers who are new to Unity&#8217;s networking system, and it will include practical code examples.<\/p>\n<h2>1. Understanding Network Connections in Unity<\/h2>\n<p>Unity provides a built-in networking system called <strong>UNet<\/strong> for creating multiplayer games. UNet is based on a client-server architecture and manages communication between clients and the server. Since 2020, Unity introduced a new <strong>MLAPI<\/strong> (Multiplayer Networking), but there are still many examples using UNet, so I will explain both.<\/p>\n<h3>1.1. Client-Server Model<\/h3>\n<p>The client-server model is a structure where the server centrally manages the state of the game and the clients communicate with the server to request and update game information. The advantage of this model is that it enables fair play. The server manages the state of all clients and processes the game logic accordingly.<\/p>\n<h3>1.2. P2P Model<\/h3>\n<p>In the Peer-to-Peer (P2P) model, each client communicates directly with each other. This model does not require a server, which reduces costs and enhances connection immediacy between clients. However, it may increase the risk of tampering and hacking, and all clients will have the same privileges.<\/p>\n<h2>2. Using UNet in Unity<\/h2>\n<p>To use UNet in Unity, you need to follow these steps:<\/p>\n<h3>2.1. Setting Up a Unity Project<\/h3>\n<ul>\n<li>Open the Unity editor and create a new project.<\/li>\n<li>Add the <strong>Unity Networking<\/strong> package via the Package Manager.<\/li>\n<\/ul>\n<h3>2.2. Configuring the Network Manager<\/h3>\n<p>The Network Manager is a core component of UNet. After creating it, set the following details:<\/p>\n<ul>\n<li>Specify the server&#8217;s port number.<\/li>\n<li>Set the maximum number of players for the game.<\/li>\n<li>Register the game object that will run as the server.<\/li>\n<\/ul>\n<h3>2.3. Implementing Basic Network Logic<\/h3>\n<p>After setting up the Network Manager, you need to write a script that starts the server and client when the game begins. Below is a sample code for setting up a basic connection:<\/p>\n<pre><code>\n    using UnityEngine;\n    using UnityEngine.Networking;\n\n    public class GameNetworkManager : NetworkManager\n    {\n        public void StartServer()\n        {\n            StartHost(); \/\/ Start server\n        }\n\n        public void StartClient()\n        {\n            StartClient(); \/\/ Start client\n        }\n    }\n    <\/code><\/pre>\n<h2>3. Monitoring Connection Status<\/h2>\n<p>Monitoring the connection status of clients during gameplay is crucial. Disconnections or delays can significantly impact the gaming experience.<\/p>\n<h3>3.1. Function to Check Connection Status<\/h3>\n<p>The following script checks the connection status and handles it appropriately:<\/p>\n<pre><code>\n    using UnityEngine;\n\n    public class ConnectionManager : MonoBehaviour\n    {\n        void Update()\n        {\n            if (NetworkClient.active)\n            {\n                if (NetworkClient.isConnected)\n                {\n                    \/\/ When connection status is normal\n                    Debug.Log(\"Client connected!\");\n                }\n                else\n                {\n                    \/\/ When connection is lost\n                    Debug.Log(\"Client disconnected!\");\n                }\n            }\n        }\n    }\n    <\/code><\/pre>\n<h3>3.2. Managing Network Events<\/h3>\n<p>It\u2019s important to manage various network events to provide appropriate feedback to players. The following code is an example of triggering events on connection success and failure:<\/p>\n<pre><code>\n    using UnityEngine;\n    using UnityEngine.Networking;\n\n    public class NetworkEvents : NetworkManager\n    {\n        public override void OnServerConnect(NetworkConnection conn)\n        {\n            Debug.Log(\"Client connected to the server!\");\n        }\n\n        public override void OnServerDisconnect(NetworkConnection conn)\n        {\n            Debug.Log(\"Client disconnected from the server!\");\n        }\n    }\n    <\/code><\/pre>\n<h2>4. Key Considerations for Multiplayer Games<\/h2>\n<p>When developing multiplayer games, there are several important factors to consider:<\/p>\n<h3>4.1. Latency<\/h3>\n<p>Latency can affect the data transmission time between clients, which can negatively impact the game&#8217;s responsiveness. Methods to reduce latency include client prediction and interpolation techniques.<\/p>\n<h3>4.2. Security<\/h3>\n<p>Security measures must be taken to ensure that all clients do not operate beyond their given rights. Technologies such as server-side data validation need to be implemented while prioritizing performance.<\/p>\n<h3>4.3. Synchronization<\/h3>\n<p>The state of game objects must be consistently synchronized across all clients. In UNet, the <code>[SyncVar]<\/code> attribute can be used to synchronize variables.<\/p>\n<h2>5. Conclusion<\/h2>\n<p>In this tutorial, we learned how to set up network connections in Unity and monitor their status. Networking is an essential element in game development, requiring accurate and stable implementation. Based on this knowledge, you can advance your multiplayer game development. Furthermore, challenge yourself to create more engaging games by utilizing modern technologies like MLAPI!<\/p>\n<p>We will provide more foundational Unity tutorials and various game development tips in the future, so please stay tuned.<\/p>\n<p><\/body><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In game development, network connections are essential for creating multiplayer games that allow multiple players to participate simultaneously. This tutorial will explain in detail how to set up network connections in Unity and monitor connection status. This article is aimed at beginner developers who are new to Unity&#8217;s networking system, and it will include practical &hellip; <a href=\"https:\/\/atmokpo.com\/w\/31979\/\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;Unity Basics Course: Network Connection Status&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[135],"tags":[],"class_list":["post-31979","post","type-post","status-publish","format-standard","hentry","category-unity-basic"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Unity Basics Course: Network Connection Status - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/atmokpo.com\/w\/31979\/\" \/>\n<meta property=\"og:locale\" content=\"ko_KR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Unity Basics Course: Network Connection Status - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"og:description\" content=\"In game development, network connections are essential for creating multiplayer games that allow multiple players to participate simultaneously. This tutorial will explain in detail how to set up network connections in Unity and monitor connection status. This article is aimed at beginner developers who are new to Unity&#8217;s networking system, and it will include practical &hellip; \ub354 \ubcf4\uae30 &quot;Unity Basics Course: Network Connection Status&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/atmokpo.com\/w\/31979\/\" \/>\n<meta property=\"og:site_name\" content=\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-01T09:04:38+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-01T11:33:51+00:00\" \/>\n<meta name=\"author\" content=\"root\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@bebubo4\" \/>\n<meta name=\"twitter:site\" content=\"@bebubo4\" \/>\n<meta name=\"twitter:label1\" content=\"\uae00\uc4f4\uc774\" \/>\n\t<meta name=\"twitter:data1\" content=\"root\" \/>\n\t<meta name=\"twitter:label2\" content=\"\uc608\uc0c1 \ub418\ub294 \ud310\ub3c5 \uc2dc\uac04\" \/>\n\t<meta name=\"twitter:data2\" content=\"3\ubd84\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/atmokpo.com\/w\/31979\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/31979\/\"},\"author\":{\"name\":\"root\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\"},\"headline\":\"Unity Basics Course: Network Connection Status\",\"datePublished\":\"2024-11-01T09:04:38+00:00\",\"dateModified\":\"2024-11-01T11:33:51+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/atmokpo.com\/w\/31979\/\"},\"wordCount\":585,\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"articleSection\":[\"Unity Basic\"],\"inLanguage\":\"ko-KR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/atmokpo.com\/w\/31979\/\",\"url\":\"https:\/\/atmokpo.com\/w\/31979\/\",\"name\":\"Unity Basics Course: Network Connection Status - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#website\"},\"datePublished\":\"2024-11-01T09:04:38+00:00\",\"dateModified\":\"2024-11-01T11:33:51+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/atmokpo.com\/w\/31979\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/atmokpo.com\/w\/31979\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/atmokpo.com\/w\/31979\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\ud648\",\"item\":\"https:\/\/atmokpo.com\/w\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Unity Basics Course: Network Connection Status\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/atmokpo.com\/w\/#website\",\"url\":\"https:\/\/atmokpo.com\/w\/\",\"name\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/atmokpo.com\/w\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"ko-KR\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\",\"name\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"url\":\"https:\/\/atmokpo.com\/w\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ko-KR\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png\",\"contentUrl\":\"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png\",\"width\":400,\"height\":400,\"caption\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\"},\"image\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/x.com\/bebubo4\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\",\"name\":\"root\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ko-KR\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g\",\"caption\":\"root\"},\"sameAs\":[\"http:\/\/atmokpo.com\/w\"],\"url\":\"https:\/\/atmokpo.com\/w\/author\/root\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Unity Basics Course: Network Connection Status - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","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:\/\/atmokpo.com\/w\/31979\/","og_locale":"ko_KR","og_type":"article","og_title":"Unity Basics Course: Network Connection Status - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","og_description":"In game development, network connections are essential for creating multiplayer games that allow multiple players to participate simultaneously. This tutorial will explain in detail how to set up network connections in Unity and monitor connection status. This article is aimed at beginner developers who are new to Unity&#8217;s networking system, and it will include practical &hellip; \ub354 \ubcf4\uae30 \"Unity Basics Course: Network Connection Status\"","og_url":"https:\/\/atmokpo.com\/w\/31979\/","og_site_name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","article_published_time":"2024-11-01T09:04:38+00:00","article_modified_time":"2024-11-01T11:33:51+00:00","author":"root","twitter_card":"summary_large_image","twitter_creator":"@bebubo4","twitter_site":"@bebubo4","twitter_misc":{"\uae00\uc4f4\uc774":"root","\uc608\uc0c1 \ub418\ub294 \ud310\ub3c5 \uc2dc\uac04":"3\ubd84"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/atmokpo.com\/w\/31979\/#article","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/31979\/"},"author":{"name":"root","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7"},"headline":"Unity Basics Course: Network Connection Status","datePublished":"2024-11-01T09:04:38+00:00","dateModified":"2024-11-01T11:33:51+00:00","mainEntityOfPage":{"@id":"https:\/\/atmokpo.com\/w\/31979\/"},"wordCount":585,"publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"articleSection":["Unity Basic"],"inLanguage":"ko-KR"},{"@type":"WebPage","@id":"https:\/\/atmokpo.com\/w\/31979\/","url":"https:\/\/atmokpo.com\/w\/31979\/","name":"Unity Basics Course: Network Connection Status - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/#website"},"datePublished":"2024-11-01T09:04:38+00:00","dateModified":"2024-11-01T11:33:51+00:00","breadcrumb":{"@id":"https:\/\/atmokpo.com\/w\/31979\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/atmokpo.com\/w\/31979\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/atmokpo.com\/w\/31979\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\ud648","item":"https:\/\/atmokpo.com\/w\/en\/"},{"@type":"ListItem","position":2,"name":"Unity Basics Course: Network Connection Status"}]},{"@type":"WebSite","@id":"https:\/\/atmokpo.com\/w\/#website","url":"https:\/\/atmokpo.com\/w\/","name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","description":"","publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/atmokpo.com\/w\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"ko-KR"},{"@type":"Organization","@id":"https:\/\/atmokpo.com\/w\/#organization","name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","url":"https:\/\/atmokpo.com\/w\/","logo":{"@type":"ImageObject","inLanguage":"ko-KR","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/","url":"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png","contentUrl":"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png","width":400,"height":400,"caption":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8"},"image":{"@id":"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/bebubo4"]},{"@type":"Person","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7","name":"root","image":{"@type":"ImageObject","inLanguage":"ko-KR","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g","caption":"root"},"sameAs":["http:\/\/atmokpo.com\/w"],"url":"https:\/\/atmokpo.com\/w\/author\/root\/"}]}},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/31979","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/comments?post=31979"}],"version-history":[{"count":1,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/31979\/revisions"}],"predecessor-version":[{"id":31980,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/31979\/revisions\/31980"}],"wp:attachment":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/media?parent=31979"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/categories?post=31979"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/tags?post=31979"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}