- Home /
Command line flag to build WebGL
The manual outlines command line options here: http://docs.unity3d.com/Manual/CommandLineArguments.html but there is no mention of building a WebGL project. Has anyone found a flag to do such with the Unity 5 Beta?
Answer by joonturbo · May 26, 2015 at 12:20 PM
Unity 5.0.1 has `BuildTarget.WebGL`
//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);
}
}
Ironic that I forgot to update this answer myself with my own gist :)
Answer by Graham-Dunnett · Nov 11, 2014 at 10:47 PM
There's not a flag for this yet.
5.0.1 has BuildTarget.WebGL. I'm currently looking to see if you can set Optimization level (slow-fast-fastest) somehow
I figured out that the following is possible, but not sure if it works (since these things aren't exactly verbose)
static void PerformBuildWebGLSlow()
{
**EditorUserBuildSettings.webGLOptimizationLevel = 2;**
BuildPipeline.BuildPlayer(GetScenes(), "Bin/webgl/", BuildTarget.WebGL, BuildOptions.None);
}
Answer by unity_sxF4kWUhnH3bzw · Jul 13, 2018 at 01:37 PM
Here is a Programmer to English translation of the answers in this thread:
There is currently no command line argument to build a WebGL player. To work around this, you can use the command line argument to run a c# script. You can create a c# script that makes calls to Unity to do the building, and then run that script from the command line.
Here is the script to make. It goes in the Assets/Editor folder of your project.
using UnityEditor;
class WebGLBuilder {
static void build() {
string[] scenes = {"Assets/main.unity"};
BuildPipeline.BuildPlayer(scenes, "WebGL-Dist", BuildTarget.WebGL, BuildOptions.None);
}
}
Then use the command line option to call the code in the c# script:
Unity.exe -quit -batchmode -executeMethod WebGLBuilder.build
Specifically, note the -executeMethod command line argument, which lets you call a method in a c# class in the project.
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
ArgumentException: targetGroup must be valid 1 Answer
xr plugin managment arkit required script 0 Answers