- Go to UGS
- Create Account/Sign In.
- Create a new project/Select an existing one.
- Select Multiplayer in left menu.
- Make sure the payment information is added.
- Click Lobby and follow the instructions.
- Click Relay -> Open Relay -> Get Started and follow the instructions.
- You have connected your unit project to the UGS
- Launch Unity Editor.
Ctrl+Shift+B- Choose a WebGL platform. Install if not installed.
- Click build.
- Select the folder for the build: server
- Done!
Ctrl+Shift+B- Select Code Optimization: "Shorter Build Time"
- Click Player Settings...
- Other Settings -> IL2CPP Code Generation : "Faster runtime"
- Publish Settings -> Compression Format -> "Disabled"
- This should speed up the assembly a bit. But don't forget to put everything back when you do the production build.
- Go to BotFather
- Type
/newbot - Give a name
- Give a username
- Copy the token. Looks like this:
8162125942:DLFcAWwYQXICFIM2Vus3sGy_OLR3LtFARlEThis is a secret key, do not give it to anyone and do not publish it anywhere. - Go to the project root folder -> server.
- Create&Open the ".env". Paste bot tokens like this:
BOT_TOKEN="YOUR_BOT_TOKEN"
SECRET_TOKEN="bfaf9e93-1a0c-4627-9df6-f7c8c0673026" //any random string [a-z , A-Z , _ , - , 0-9]Telegram bot requires an SSL connection to the server. Therefore, to connect your development environment, you need ngrok.
- Go to ngrok and create account.
- Go to this page to get your auth token.
- Go to the project root folder -> server.
- Create or Open the ".env". Paste your auth tokens like this:
NGROK_AUTHTOKEN="YOUR_AUTH_TOKEN"
NODE_ENV="development" - Run Build each time changes were made.
- Go to the project root folder -> server in terminal.
- At the first launch:
npm install. - Run
node server.js
- Check the Template:
Ctrl+Shift+B- Click
Player Settings... - Expand
Resolution and Presentation-> Under WebGL Template Selectprod
- Open your bot on any two Telegram clients.
- Send anything to get an answer with a button -> click on the button -> the game will be launched (it may take time).
- Click "Online"
- Click "Play" - to automatically/randomly find an opponent (since there is only you in the test environment, your opponent will be your second open client). Important! First, click "Play" on one client, wait a few seconds, and then click "Play" on the other.
- Click "Play With Friends" - To create rooms and a join code.
- If the second device does not have a camera, enter the code in the field and press
> - If the second device has a camera, click "Scan QR" and scan the QR.
- If the second device does not have a camera, enter the code in the field and press
- You can simulate a win by clicking the "Win" button in the game.
If you want to test without Telegram, you can open the game as a regular web page. But then you will need a Telegram Web App plug to enable it:
Ctrl+Shift+B- Click
Player Settings... - Expand
Resolution and Presentation-> Under WebGL Template Selectdev - Re-Build
- Start the server -> links will be printed to the terminal -> click on them. Open in different browsers and test.
- Run Build
- The root directory of the project contains the server folder - this is your node js server, which you can deploy to any hosting you like.
- Create an account on Railway
- Create new github repo.
- Go to /server - Copy&Paste the folder somewhere outside the project (outside your .git) <- Place future builds in this folder.
- Open the terminal in the copied folder:
npm installgit initgit add .git commit -m "first"git branch -M maingit remote add origin https://github.com/...your_created_git_repogit push -u origin main- Go to Railway
- Select Deploy from Git Repo
- Select Configure GitHub App and link the created project.
- The application will be deployed automatically with each git push.
- Select the app in the Railway dashboard. The menu opens. Select the Variables tab.
- Setup env:
- BOT_TOKEN - your production telegram bot token
- HOOK_PATH - any random string
a-zA-Z_-0-9 - NODE_ENV - You can leave it blank or enter production
- PORT - 433
- SECRET_TOKEN - any random string
a-zA-Z_-0-9 - APP_ENDPOINT - Url of your application. Click the Settings tab.
"Networking" -> "Public Networking" -> Copy/Paste.https://nodejs-production-****.up.railway.app
Explore: Assets/Plugins/plugin.jslib
This script is executed in the js environment in your browser, so it has access to window and telegram WebApp objects. The Unity script can call all the declared functions and pass primitive data (or complex data in the form of a json string).
Explore: Assets/ERS/Scripts/Telergam/TelegramConnect.cs This script declares the same functions as in plugin.jslib
//Call in Unity c#
TelegramConnect.Hello();
//Will trigger functions in the plugin.jslib
Hello: function () {
window.alert("Hello, world!");
},
//So the alert will be displayed in the browserExplore: Assets/WebGLTemplates/prod/index.html
unityInstance.SendMessage("Object name", "Receiver function", "string or json string")
From javascript, sends a string to the GameObject on the Unity scene that contains the script with the specified function.
//Call in javascript
window.unityInstance.SendMessage("TelegramController", "SetWebAppUser", JSON.stringify(window.Telegram.WebApp.initDataUnsafe.user));
//Will trigger GameObject on the scene named "TelegramController" with the attached script "TelegramController.cs" that contains the function "SetWebAppUser"
public void SetWebAppUser(string data)
{
var webAppUser = JsonUtility.FromJson<WebAppUser>(data);
}
//So the user will be passed as a json string to the Unity scriptExplore: Assets/Scripts/Telegram directory - to better understand how it works.
Install failed: Validation Failed
Either Can't load WebGL or open the project or Unity at all.
It seems that every year, instead of improving the quality, Unity only increases the number of bugs.
This solution bypasses the Bug Hub Unity Hub:
- If you haven't already, try to install an editor in the Hub (this will fail)
- In Unity Hub, go to preferences -> installs. Find the Downloads location.
- Open a File Explorer, and navigate to the specified Downloads location
- In your File Explorer, there should be an installer(UnitySetup...) in the Downloads location.
- Click to install.
- Run Unity through the installed editor.
Unable to parse Build/Hot xxx.framework.js.br! If using custom web server, verify that web server is sending .br files with HTTP Response Header "Content-Encoding: br". Brotli compression may not be supported over HTTP connections. Migrate your server to use HTTPS.
The server should set a header when it returns a compressed file:
'Content-Encoding':'br'; // if Brotli compression used
'Content-Encoding': 'gzip'; // if Gzip compression used
'Content-Type': 'application/wasm';Invoking error handler due to RuntimeError: null function or function signature mismatch
Do not try to hang several scripts on one GameObject and call them - collect all the necessary functions in one script and hang only one script on the receiver(GameObject).
ERR_NGROK_3200, ERR_NGROK_xxx
The server is not running, or the server has stopped due to an error. Restart the server.
I launch the game on two devices, but the game does not start, I see the message "Waiting for players"
This is not a problem in the code, but in Unity services. Don't launch the game at the same time, wait until it starts on one device and then launch it on the other. In a real environment where you have thousands of players per minute looking for an opponent, this will not be a problem.
The size of the build is too large for web platforms.
Oh, yes! Based on the build log, the Unity logo takes up the most space🤣🤣🤣, which can be removed by purchasing a Unity license.



