HMS Unity Plugin — Integration

Sunandhini Muralidharan
Huawei Developers
Published in
6 min readJun 20, 2023

Unity is Cross-Platform game engine developed by Unity Technologies. We can merge the HMS capabilities and Unity’s powerful Engine using HMS Unity Plugin

Introduction

The Unity game engine started as Mac OS X game engine which later extended to support various desktop, mobile, console and virtual reality platforms. We can create 2D and 3D games along with interactive simulations using Unity Engine. We will be learning about how to integrate HMS capabilities into Unity and use it. This article will give a step-by-step overview of the procedure.

HMS Unity Plugin

The HMS Unity plugin helps you integrate the full power of Huawei Mobile Services into your game developed with Unity.

Also you can access other features such as Connect API which provides RESTful APIs that can be used to customize services provided by AppGallery Connect or implement process automation, thereby improving your work efficiency.

HMS Unity plugin is very easy to use and learn. This plugin is open source and available in GitHub. We are using the V2.3.3 version of the Plugin.

HMS Unity Plugin Integration

The steps for using the HMS Unity Plugin in your unity project is given below.

1. Create Unity Account

Before you start using Unity, you need to register for an Unity account. This is required to download UnityHub, Unity Editor and other resource files from Unity Asset Store. To register for an Unity account, click here.

2. Install Unity Editor

The official website recommends installation of Unity Hub before installing Unity Editor.

  • Unity Hub: It is a tool for managing Unity projects, Unity Editor, licenses, and additional components.
  • Unity Editor: It is a platform for you to develop projects. It is similar to Android Studio and can be used to compile and run projects.

Download the Unity Hub: https://unity.com/download.

Once Unity Hub is downloaded, click on the button to install Unity Editor. I installed Unity 2020.3.48f1 (64-bit) version. Unity 2022.3.0f1 is also available for download. In Licenses, I use personal license.

(Optional) Installing Visual Studio

Visual Studio is the script editor for Unity. It will be automatically installed when installing Unity Editor. But, if some error occurs, you can install Visual Studio by yourself. If the installation is successful, we can associate Visual Studio as shown below.

NOTE:

It is important to have uncontrolled write permissions in the path where you are installing UnityHub and Unity Editor as this is needed while installing the Android SDKs. You can change the path of installation accordingly.

3. Create your Unity Project

In your Unity Hub, Click on New Project and create a new project according to your specification.

Click on File -> Build Settings -> Android -> Switch Platform

4. Register your App at Huawei Developers

Step 1: Login to AppGallery Connect (AGC) and create new project. Enter the details as requested and create it.

Step 2: Create an app inside the project. Select the App category as Game and the package name must end with .huawei or .HUAWEI.

Step 3: Generate a Keystore file and get the Signing Certificate Fingerprint. Add the Signing certificate fingerprint in your app in AGC.

NOTE:

Please Click here to know more about how to generate Keystore file and Signing Certificate Fingerprint.

5. Import HMS Unity Plugin into your Project

Step 1: Download the Unity Plugin (.unitypackage extension) from the link given below

Step 2: In Unity Project, select Assets -> Import Package -> Custom Package. Select the HMS Unity Plugin that you have downloaded in previous step. Select the entire package and click on Import.

6. Update agconnect-services.json

Go to Manage APIs Section in AGC. Select the necessary Kits that needs to be used in your game and then download the agconnect-services.json file.

Copy/Replace the downloaded agconnect-services.json file into your Unity Project’s Assets -> Streaming Assets folder.

Then, Go to File -> Build Settings -> Player Settings -> Other Settings. Enter the package name that you gave while creating the App in AGC (The package name is also available in agconnect-services.json). Also, make the Minimum API Level to 21.

7. Connect you game with Huawei Kits

Go to Huawei -> Kit Settings. Select the kits needed for your Unity Game. The Plugin will automatically create Game Objects needed for the kits. These Game Objects have DontDestroyOnLoad implemented so that the reference is not lost. After V2.2, no visible Kit Manager Game Object seen on the scene.

8. Use the Kits

You need to use the kit managers and functions in that kit managers to use the kit functionalities.

After finishing coding, go to File -> Build Settings -> Player Settings -> Publishing Settings and enter the Keystore details. This is required to build APK.

Tips and Tricks

  • Installation of UnityHub should happen in a directory that should have write permissions for the user.
  • Make sure Kits are enabled in AGC before downloading agconnect-services.json.
  • The package name in Player Settings -> Publishing Settings and in agconnect-services.json should be same.
  • If you are using android studio for android SDK and local JDK, select appropriate path in Edit -> Preferences ->External Tools.

Conclusion

This article focuses on how to do complete integration of HMS Unity Plugin with your Unity Game. Thus, the entire HMS Capabilities can be merged with powerful Unity to give the game users a very rich experience.

References

--

--

Sunandhini Muralidharan
Huawei Developers

HMS, Android Studio, Java, Flutter, Dart Programming, HMOS