Skip to content

Instantly share code, notes, and snippets.

@jagwire
Created December 11, 2014 15:12
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jagwire/0129d50778c8b4462b68 to your computer and use it in GitHub Desktop.
Save jagwire/0129d50778c8b4462b68 to your computer and use it in GitHub Desktop.
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
Copy link

Glorious starting point, thank you

@peteshand
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