How to Create a Chat System in Unity With Mirror

How to Create a Chat System in Unity With Mirror

One of my Unity projects utilizes UNet which is a low level multiplayer API which is now deprecated. I needed a good networking solution that supports basic server-client communication and data transport. In search for a replacement, I quickly found Mirror.

Learn how to:

  1. Set up Mirror in Unity
  2. Create a chat box which resembles natural messaging capabilities such as infinite scrolling, send message on enter, etc.
  3. Develop a C# script to facilitate server client communication

Requirements:

  1. Basic knowledge of Unity editor and C# scripting
  2. Know at a high level what server client system is

Introduction

One of my Unity projects utilizes UNet which is a low level multiplayer API which is now deprecated. I needed a good networking solution that supports basic server-client communication and data transport. In search for a replacement, I quickly found Mirror.

Image for post

Mirror Logo. Image source

Image for post

Good reviews and seems like it’s beginner friendly. Image source

Until now it seems to work really well. Everything is good to understand after using a beginner tutorial and the documentation. — Acdia, Unity Asset Store

One way I experimented with Mirror to make sure it fits my application’s needs was to create a chat system. I found several helpful tutorials online for setting up a chat box and network manager. Here I will aggregate those tutorials and show a comprehensive source for creating a chat system in Unity. This tutorial assumes that you have already installed Unity (preferably updated to the latest version or 2018.4 LTS and higher for compatibility with Mirror).


Installations

The first step is to install Mirror. It is a Unity Package so installation is very simple. Go to the Mirror page on Unity asset store (create a Unity account if you haven’t) and click on “Add to My Assets”. Follow the installation process to open with Unity, download the package, and install into your app. In order for the Mirror _GameObjects _to show up, restart Unity.

Setting up Network Manager

Once you have restarted Unity, create an Empty GameObject and name it “NetworkManager”. This will contain Mirror components needed to establish our server and player connections. To NetworkManager, add a _NetworkManager _component (which will also add Telepathy Transport) and a NetworkManagerHUD. Leave all fields as their presets for now.

Setting up the Chat Box

If you are developing a game, the client could be an object or character in your game. When players join the game, they are represented as that object or character. Since we are creating a standalone chat, any of the default shapes should work. I chose a cube, but feel free to pick one of the other standard 2D or 3D shapes. Add a _Cube _object to the scene.

chat unity c-sharp-programming

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

C programming for Beginners | Learn C Programming | C Language

C Language is an evergreen language and is used widely across different industries, This C programming is a must for students and working professionals to become a great Software Engineer especially when they are working in Software Development Domain. Great Learning brings you this live session on "Introduction to C". In this live session, we will be covering major concepts in C Programming such as Different Variables, Different Data Types that are being used, its Operators, Flow control statements, Structure, and lot more.

5 Best C# (C-Sharp) Programming Courses for Beginners in 2020

In this article, I am going to share some of the best courses to learn C# or C-Sharp in 2020. These courses are suitable for both beginners and experienced programmers who want to fill gaps in their C# knowledge.

Object Oriented Programming in C++ | C++ OOPs Concepts | Learn Object Oriented C++

C++ is general purpose, compiled, object-oriented programming language and its concepts served as the basis for several other languages such as Java, Python, Ruby, Perl etc.

Classes and Objects in C++ | C++ Programming Language - Part2

This Edureka video Classes and Objects in C++ will help you to get started with C++.

Introduction to C++ Programming Language | C++ Tutorial for Beginners - Part 1

This Edureka video on Introduction to C++ Programming will help you to get started with C++.