Ever built a cross-platform mobile multiplayer game in Unity and wanted to add in some custom group video chat capabilities? If you answered yes, first let me tip my hat to you because that's a big task! If you answered no (or yes but are still interested in Unity voice chat as you play), today is your lucky day! I will spend some time explaining how to easily add cross-platform video communication to your existing Unity project.
For those that donāt have a multiplayer game but are still interested in Unity multiplayer chat? Well, donāt worry because youāve come to the right place. I chose to use a pre-builtĀ Tanks!!! reference projectĀ (based on Unityās popularĀ Tanks tutorial) which has a niceĀ set of video tutorialsĀ for those interested in learning more about the game build.
Before we get started on building Unity voice chat for multiplayer platforms, there are a few prerequisites for anyone reading this article.
Prerequisites
- UnityĀ and aĀ Unity Developer account
- Knowledge of how to build your Unity project forĀ iOSĀ andĀ Android apps
- A cross-platform mobile multiplayer Unity game (I chose to useĀ Tanks!!!)
- An understanding of C# andĀ scripting within Unity
- AnĀ Agora developer account
- At least two mobile devices (one iOS & one Android is ideal)
Project Setup
If you plan to use your own existing project to build your Unity voice chat, go ahead and open it now and skip down to āIntegrating Group Voice Chatā.
For those readers that donāt have an existing project, keep reading (the next few sections are for you).
New UnityĀ Project
Please bear with me as the basic setup has a few steps and Iāll do my best to cover it swiftly with lots of images. Letās start by opening Unity, creating a blank project.

I named my project Tanks!!! withĀ Agora
If youāve previously downloaded the Tanks!!! asset package, you can selectĀ Tanks!!!
Ā using the āAdd Asset Packageā button.

If you donāt have the asset downloaded, create a new project andĀ download it from the Unity Store.

Download and import theĀ project.
There are a couple more steps to getting the Tanks!!! reference project ready for building on mobile. First, we need to enable Unity Live Mode for the project through the Unity dashboard. (select project ā Multiplayer ā Unet Config).

Set max players to 6 even though Tanks!!! limits games to 4 players and clickĀ save.

Once Unity Live Mode isĀ enabled.
Building forĀ iOS
Now that we have Unityās multiplayer enabled, we are ready to build the iOS version of the online video chat. Letās start by opening our Build Settings and switch our platform to iOS and build the project for testing.

After switching platforms to iOS make sure to update the Bundle Identifier.
Please note: You need to have Xcode installed and set up before attempting to build the Unity voice chat project for iOS.

When building for the first time, I create a new folder āBuildsā and save the build asĀ iOS.

After the project has successfully been built for iOS, we will see the project in theĀ BuildsĀ folder.
Letās openĀ Unity-iPhone.xcodeproj
, sign, and build / run on our test device.

I enabled automatic signing to simplify the system signingĀ process.
Donāt start celebrating just yet. Now that we have a working iOS build, we still need to get the Android build running.
Building forĀ Android
Android is a bit simpler than iOS since Unity can build, sign, and deploy to Android without the need to open Android Studio. For this section Iām going to assume everyone reading this has already linked Unity with their Android SDK folder. Letās start by opening our Build Settings and switching our platform to Android.
Before we try to āBuild and Runā the project on Android we need to make a couple adjustments to the code. Donāt worry, this part is really simple: we only need to comment out a few lines of code, add a simpleĀ return
Ā statement, and replace one file.
Some background:Ā The Tanks!!! Android build contains theĀ EveryplayĀ plugin for screen recording and sharing your game session. UnfortunatelyĀ Everyplay shut downĀ in October 2018 and the plugin contains some issues that if not addressed will cause the project to fail to compile and to quit unexpectedly once it compiles.
The first change we need to make is to correct a mistake in the syntax within the Everplay plugināsĀ build.gradle
Ā file. Start by navigating to our projectāsĀ Plugins
Ā folder and click into theĀ Android
Ā folder and then go into theĀ everyplay
Ā folder and open theĀ build.gradle
Ā file in your favorite code editor.

Now that we have the Gradle file open, select all and replace the default with the code below. The team that built Tanks!!! updated the code on GitHub, but for some reason it didnāt make its way into the Unity Store plugin.

The last change we need to implement is to disable EveryPlay. Why would we want to disable EveryPlay, you may ask. That's because when the plugin tries to initialize itself it causes the Android app to crash. The fastest way I found was to update a couple lines within theĀ EveryPlaySettings.cs
, (Assets ā Plugins ā EveryPlay ā Scripts) so that whenever EveryPlay attempts to check if itās supported or enabled, we returnĀ false
.

(Assets ā Plugins ā EveryPlay ā Scripts ā EveryPlaySettings.cs)
Now that EveryPlay works, we are finally ready to build the project for Android! Within Unity open theĀ Build SettingsĀ (File > Build Settings), selectĀ AndroidĀ from theĀ Platform list, and clickĀ Switch Platform. Once Unity finishes its setup process, open theĀ Player Settings. We need to make sure our Android app also has a unique bundle id, I choseĀ com.agora.tanks.voicedemo
.

Integrating VoiceĀ Chat
For this project I chose to use the Agora Voice SDK for Unity, because it makes implementation into our cross-platform mobile project really simple.
Letās open up the Unity Store and search for āAgora voice SDKā.


Once the plugin page has loaded, go ahead and clickĀ Download.Ā Once the download is complete, click andĀ ImportĀ the assets into your project.
We need to create a script to interface between our game and the Agora Voice SDK. Open the LobbyScene, select the PersistantUIAudio Game Object, and add a C# Script component, AgoraInterfaceScript.cs
. Next, letās open the C# file in Visual Studio.

There are two important variables that we need to declare:
static IRtcEngine mRtcEngine;
public static string appId = "Your Agora AppId Here";
Be sure to replaceĀ Your Agora AppID Here
Ā with anĀ Agora AppIDĀ fromĀ your Agora developer dashboard. TheĀ mRtcEngine
Ā needs to be a static so the reference doesnāt get lost when it gets called duringĀ OnUpdate
.Ā Also theĀ appId
should beĀ public
Ā andĀ static
Ā so that we can reference it from other scripts within the game.
In the interest of time and keeping this article concise, Iāve included the code of theĀ AgoraInterface.cs
Ā below. Let's skim through it together quickly.
First we notice that on Start, we include some logic to check/request the Permissions for Android. Next we initialize the Agora RTC Engine using ourĀ appId
Ā and then we attach some callback functions for the various engine events (pretty straightforward and self explanatory). The main one we care about is mRtcEngine.OnJoinChannelSuccess, as this one will log to the console when weāve successfully joined the channel.
The final critical function is theĀ Update
. While the Agora RTC Engine is active (not null) we want to call the engineāsĀ .Poll()
Ā method. This is crucial for the plugin to work!

This code is generic and can be applied to any Unity project that includes the Agora Voice SDK.
You may have noticed that we are missing methods to actuallyĀ Join/LeaveĀ the channel. Letās start with leaving the channel, create a new C# script,Ā LeaveHandler.cs
,Ā and we want theLeaveHandler
Ā to get called whenever the user returns to theĀ Main Menu.Ā The simplest way is to tap into theĀ OnEnable
method for one of theĀ Game ObjectsĀ that gets enabled when that part of theĀ LobbyScene
Ā is activated.

TheĀ Game ObjectĀ we are looking for isĀ LeftSubPanel
. It's a child ofĀ MainPanel
, which is a child ofĀ MenuUI
.

Within the Tanks!!! game there are two ways to join a multiplayer game, eitherĀ Create a GameĀ orĀ Find a Game. These are the two areas where we want to add in our command to join the channel.
Letās start in order, navigate into the UI Scripts folder (Assets ā Scripts ā UI) and openĀ CreateGame.cs
. If we scroll down toĀ line 61
Ā we can see that this is where the game does the matchmaking, and we can add some logic to connect to the channel. Start by including the Agora SDK library.
using agora_gaming_rtc;
Within theĀ StartMatchmakingGame()
Ā starting onĀ line 78
Ā weāll add in some logic to get a reference to the Agora RTC Engine (that's currently running), and then use the user input (m_MatchNameInput.text
) as the channel name.

StartMatchmakingGame() including call to join channel
Now we need to open theĀ LobbyServerEntry.cs
Ā (Assets ā Scripts ā UI) and add logic for users thatĀ Find a Game to also be able to join the same channel.
Letās openĀ LobbyServerEntry.cs
Ā in Visual Studio and scroll down toĀ line 63
, where we can see theĀ JoinMatch()
. Starting at line 80 let's add some code similar to that above.

So, that'sĀ it!
Weāve integrated the Agora SDK, and now we are ready to build and test the multiple user game with Unity chat on both iOS and Android. We can follow the same steps we did above, for building and deploying!
Thanks for following along, feel free to leave a comment or question below!
Other Resources
- The complete API documentation is available in theĀ Document Center.
- For technical support, submit a ticket using theĀ Agora Dashboard.