Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Unity command line script to build WebGL player
//place this script in the Editor folder within Assets.
using UnityEditor;
//to be used on the command line:
//$ Unity -quit -batchmode -executeMethod WebGLBuilder.build
class WebGLBuilder {
static void build() {
string[] scenes = {"Assets/main.unity"};
BuildPipeline.BuildPlayer(scenes, "WebGL-Dist", BuildTarget.WebGL, BuildOptions.None);
}
}
@TylerCode

This comment has been minimized.

Copy link

TylerCode commented Jul 25, 2018

Glorious starting point, thank you

@peteshand

This comment has been minimized.

Copy link

peteshand commented Aug 30, 2019

When running this script with the SampleScene plus a cube in 2019.1.0f2 on either Window or Mac the output dir is empty. If i build via the unity GUI it builds correctly. Has anyone else had this issue?

Edit:
The issue I was having was due to that fact that my output dir was different and it had a trailing "/"
eg: "WebGL-Dist/" instead of "WebGL-Dist"

Solution found here:
https://forum.unity.com/threads/unable-to-build-from-command-line.730970/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.