Andrzej Osowski
Andrzej Osowski

Reputation: 43

Cannot build Unity WebGL project from script

I have a problem with building Unity Project on WebGL target. This only appeares when I'm trying to build from script. When I build it from Unity project builds fine. I think it can also be important, I'm running this methot from powershell script

PS Script:

$unityPath = "C:\Program Files\Unity\Editor\Unity.exe"
$unityParameters = "-batchmode -projectPath `"$($repo)\`" -username USERNAME -password PASS -executeMethod `"BuildScript.PerformBuild`""
$buildProcess = Start-Process -FilePath $unityPath -ArgumentList $unityParameters -Wait -PassThru

My code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using UnityEditor.Build.Reporting;

public class BuildScript
{
     public static void PerformBuild()
     {
         var projectName = "scene_1";
         Debug.Log("### BUILDING ###");
         EditorUserBuildSettings.SwitchActiveBuildTarget(BuildTargetGroup.WebGL, BuildTarget.WebGL);
         var report = BuildPipeline.BuildPlayer(
             new[] {$"Assets/Scenes/{projectName}.unity"}, 
             $"Build/Win/{projectName}.exe", 
             BuildTarget.WebGL,
             BuildOptions.None);
         
         Debug.Log("###   DONE   ###");
 
         Debug.Log(report);
         EditorApplication.Exit(1);
     }
}

Error I get in report:

Switching to WebGL:WebGLSupport is disabled

...

DisplayProgressNotification: Build Failed Error building player

Error building player because build target was unsupported

Upvotes: 3

Views: 2889

Answers (1)

Tomasz Juszczak
Tomasz Juszczak

Reputation: 2340

Please check if you have WebGL support installed at eg: C:\Program Files\Unity\2020.1.5f1\Editor\Data\PlaybackEngines\WebGLSupport

This error Switching to WebGL:WebGLSupport is disabled says that WebGLSupport is probably missing from you Unity installation.

Please double check that you are using the same installation of Unity in the script and in the Editor. You can check your path in UnityHub via Show in Explorer option enter image description here

Upvotes: 2

Related Questions