Modify Unity WebGL Build URL

Viewed 988

How to change the URL of the Unity WebGL build? The build settings do not have any setting to change the URL or the port number. However here are my findings.

enter image description here

enter image description here

The following path contains the build tools for WebGL

Unity\Hub\Editor\2019.4.9f1\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools

And these are the build-tools for WebGL

Brotli/
data/
Demangle.js
DynamicJslibLoader.js
Emscripten/
emscripten.config
Emscripten_FastComp_Win/
Emscripten_Win/
ExceptionLogger.js
lib/
prejs/
SimpleWebServer.exe*
SimpleWebServer.pdb
uglify-js/
UnityLoader.js
UnityLoader.min.js
WebGLTemplates/
websockify/

Unity uses the SimpleWebServer executable to run the server locally. This program takes the following parameters

usage: SimpleWebServer.exe source_directory [port] [pid] [<wasmEncoding>]

Is there anywhere we can set the port and pick the directory when this happens in the WebGL build process?

1 Answers

I don't know how to set the port for Unity's web server.

To test the web build locally you can use any webserver (apache, IIS, python, etc.) instead of relying on the build and run button in Unity.

You can install python3 if you don't have already and run this from the web build directory:

$> python -m http.server 8080

Now you can run your game in browser by going to http://localhost:8080

Related