AirConsole Unity Plugin
The Unity-Plugin is a C# wrapper for the AirConsole Javascript API. With the plugin, Unity serves you the needed screen.html file inside the Editor and creates a screen.html file after an WebGL build export.
Before you start installing the plugin, be aware that because we support such a wide range of Unity versions, some Unity versions have some known issues when importing the plugin or when building for a specific platform. Below you will find the list of known issues and their fixes:
Affected versions | Description | Solution |
---|---|---|
Unity 2022+ | After trying to build for Android TV you may get this error: mainTemplate.gradle is using the old aaptOptions noCompress property definition does not include types defined in unityStreamingAssets constant. | Edit Assets/Plugins/Android/mainTemplate.gradle and launcherTemplate.gradle to add/replace the aaptOptions section to the following: aaptOptions {
noCompress = ['.ress', '.resource', '.obb'] + unityStreamingAssets.tokenize(', ')
ignoreAssetsPattern = "!.svn:!.git:!.ds_store:!*.scc:.*:!CVS:!thumbs.db:!picasa.ini:!*~"
}**PACKAGING_OPTIONS** Check Unity support for more details. |
Unity 2021+ | After importing the AirConsole plugin into Unity you may get this error: Multiple precompiled assemblies with the same name Newtonsoft.Json.dll included on the current platform. [...] | Delete the following plugin file (It is now included in Unity directly and is not needed in newer Unity versions): Assets/AirConsole/plugins/Newtonsoft.Json.dll |
Unity 2018.3 | After importing the AirConsole plugin into Unity you may get: The type or namespace name 'ILGenerator' could not be found (are you missing a using directive or an assembly reference?) and The type or namespace name 'DynamicMethod' could not be found (are you missing a using directive or an assembly reference?) | Set the API Compatibility Level to .NET 4.x in the Player Settings of your selected Platform. Check AirConsole FAQ for more details. |
Download from Github
Download the newest AirConsole-Unity-Plugin on our GitHub repository. You can find the newest ".unitypackage" file in the "Builds" folder.
Download from Assetstore
Learn the basics of how to make an AirConsole game in Unity in just 4 minutes.
To import the plugin, click on Assets > Import Package -> Custom Package and choose the downloaded *.unitypackage file.

Make sure that all assets are selected and click on "Import".

Instantiate AirConsole object
To set up the communication inside a scene, you have to instantiate the AirConsole object. In the Hierarchy window, click on Create > Create Other > AirConsole.

The AirConsole object offers you the following options:
Option | Description |
---|---|
Browser Start Mode | As soon as you press the “Play” button in Unity, your default browser will open the AirConsole simulator in the chosen mode. |
Controller Html | Link your controller.html file to this inspector variable, otherwise you can’t start the AirConsole simulator and you will get an error message. (Note: if your controller needs additional files like images or fonts, put them in the folder “Assets/WebGLTemplates/AirConsole”) |
Auto Scale Canvas | This option is enabled by default and scales your final webgl canvas automatically to the window size. The aspect ratio will be kept during the scaling. |

Here is a simple example where the controller sends "How are you?" to the screen and the screen replies with "Full of pixels!"
Include the AirConsole Javascript API in your controller.html file:
/controller.html
Unity
To be able to receive a message in Unity, create a new Unity MonoBehaviour class and include these namespaces:
Add an event handler in the Start method of the MonoBehaviour class:
When you send an object like this one on the controller.html side:
You can parse the object in Unity like this:
To send the same data from Unity you can use dynamic vars:
To test your game, just hit the “Play” button inside the Unity-Editor. If you want to test the final WebGL-Build, choose the right AirConsole Template in the PlayerSettings first (For Unity versions 2020 and up choose the AirConsole-2020 template, for previous Unity versions choose the AirConsole template):

Now you can export your Unity project in the Build-Settings (choose “Build” instead of the “Build and run” button). As soon as your build is exported, the button “Open Exported Port” on the AirConsole object in your scene will appear. By pressing this button, the AirConsole simulator will start with your final build.

- AirConsole/Examples/Basic/basic.scene: In this example all possible API functions are listed & used.
- AirConsole/Examples/Pong/pong.scene: This example contains a simple pong game with a specific controller.

You can open the settings window by clicking on the "Settings" button on the inspector of the AirConsole object or by navigating over the menu bar AirConsole > Settings.

In the "Settings" window, the ports for the internal web socket and web server can be changed, should the default ports already be occupied.
You can stop and restart the internal web server in case the AirConsole simulator isn't working properly.

AirConsole also provides an AndroidTV app, so that user can play your games also on a smart-tv. Please read the "AirConsole Unity on AndroidTv" documentation to adapt your game for AndroidTV.