foreword
Recently, due to the needs of the project, I started to study the knowledge related to the development of WeChat mini-games by Unity. During the period, I encountered various pitfalls, and the information I checked online was basically similar, and I couldn't solve the problems I encountered. This article is specially used to record the process, so that others can refer to it when they encounter the same problem.
development environment
-
The Unity version is recommended to use version 2021.2.5 according to the WeChat mini game plug-in documentation. It is measured that versions 2021.3.x and above can be used.
-
Install the latest long-term support version of NodeJs.
-
For mini game account registration, please refer to WeChat Official Documentation WeChat Open Documentation
-
WeChat Developer Tools (mini game version)
Precautions
-
The applet category settings must be set as shown in the figure below.
- Otherwise, there will be no ability map function in the -> growth of the applet menu. The next steps will present a series of problems. For example, the program converted with the Unity WeChat mini-game plug-in cannot be imported into the WeChat developer tool normally. And there is an error that cannot be compiled and prompts " the entry app.json file was not found , or the file failed to read,...".
- Enable the [High Performance Mode] and [Quick Adaptation] functions in the Mini Program->Growth->Capability Map->Production Efficiency Improvement Package. As shown below
development steps
Develop Unity games
It is recommended to use the simplest example first to test whether the conversion process and development environment are correct.
Install the WeChat mini game unity conversion plug-in
Download plug-in minigame-unity-webgl-transform: Unity WebGL WeChat Mini Game Adaptation Solution
In the project opened by Unity Editor, right-click on the project to import package->custom package and select the downloaded plug-in.
After the installation is successful, you will see [WeChat Mini Game] in the UnityEditor menu.
Compile the Unity project
This step is not repeated
Setting up Unity WebGL
File->Build settings in Unity Editor. As shown below
Convert WeChat Mini Game
Set as shown below. Required fields:
- The game appid is the appid generated when the WeChat applet is registered
- Mini game project name
- export path. Converted program storage path
- The first package resource loading method. Select the small game package (the reason is that there is no own CDN server yet)
Click to export WebGL and convert to mini game. program conversion
Possible problems with the conversion process
- The error node.exe does not exist, first check whether Nodejs is installed; if it is installed, follow the steps in the figure to set it up. Custom Node Path is set to your own Nodejs installation path.
- The Unity 2021 version uses Embeded Symbols, and the code package contains a large volume of function names. Please use the code subpackage tool to optimize before release. According to the error prompt, open the corresponding source code, and find that this error will definitely appear only in versions above Unity2021, and it will not affect the follow-up work. If you have obsessive-compulsive disorder like me, you can manually comment out this line of code.
WeChat developer tools import project
In the mini game menu -> directory -> select the Minigame directory under the directory where Unity converts the mini game settings.
Because there is no cloud server, the back-end service chooses not to use cloud services. After confirming, you can compile normally, debug and run your own mini-game.
In the mini game menu -> directory -> select the Minigame directory under the directory where Unity converts the mini game settings.
Because there is no cloud server, the back-end service chooses not to use cloud services. After confirming, you can compile normally, debug and run your own mini-game.