Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 206
Andrzej Osowski Avatar asked Jul 17 '26 03:07

Andrzej Osowski


1 Answers

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

like image 68
Tomasz Juszczak Avatar answered Jul 21 '26 22:07

Tomasz Juszczak



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!