Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Question WebGL build is failing because of UnityEngine.WebGLInput

Discussion in 'Web' started by diego_timining, Mar 23, 2022.

  1. diego_timining

    diego_timining

    Joined:
    Mar 17, 2022
    Posts:
    3
    Hi, I'm trying to build my project in WebGL using the terminal, however I got build errors in the UnityEngine.WebGLInput.captureAllKeyboardInput method. This issue does not occur if I generate a build from the editor set to the WebGL platform. I honestly have no idea why it's failing, I'm using version 2020.3.21f1 of unity

    Compilation errors: (I checked the references in the assembly definition and everything is ok, the problem is another)
    Code (CSharp):
    1. Assets\Plugins\WebGLSupport\WebGLInput\WebGLInput.cs(271,13): error CS1069: The type name 'WebGLInput' could not be found in the namespace 'UnityEngine'. This type has been forwarded to assembly 'UnityEngine.WebGLModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' Consider adding a reference to that assembly.
    2. Assets\Plugins\WebGLSupport\WebGLInput\WebGLInput.cs(279,13): error CS1069: The type name 'WebGLInput' could not be found in the namespace 'UnityEngine'. This type has been forwarded to assembly 'UnityEngine.WebGLModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' Consider adding a reference to that assembly.
    3. Assets\Plugins\WebGLSupport\WebGLInput\WebGLInput.cs(398,13): error CS1069: The type name 'WebGLInput' could not be found in the namespace 'UnityEngine'. This type has been forwarded to assembly 'UnityEngine.WebGLModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' Consider adding a reference to that assembly.
    The line of discord
    Code (CSharp):
    1. #if UNITY_WEBGL && !UNITY_EDITOR
    2.             UnityEngine.WebGLInput.captureAllKeyboardInput = false;
    3. #endif
    4.         }
     
  2. ebrkar

    ebrkar

    Joined:
    Jan 14, 2020
    Posts:
    1
    Hi @diego_timining

    I have used the https://github.com/kou-yeung/WebGLInput package. I also build without problems in the editor, but I get an error through the command line.

    When compiling, I get the same error. According to your statement, you checked the references. But I don't see the assembly definition file. Is this file of your own creation?
     
  3. AdViventes

    AdViventes

    Joined:
    Dec 17, 2016
    Posts:
    11
  4. unityruba

    unityruba

    Unity Technologies

    Joined:
    Nov 6, 2020
    Posts:
    278
    Can you paste the exact commands you use in the terminal to build the project so I can test this issue and reproduce it? (just in case you do something slightly different from me)
     
  5. AdViventes

    AdViventes

    Joined:
    Dec 17, 2016
    Posts:
    11
    Right now I have no issues, because I used solution in github link above.
    However, if you still need my CLI line, then here it is:
    -projectPath $PROJECT_PATH -batchmode -nographics -buildPath $BUILD_PATH -isDevelopmentBuild false  --executeMethod BuildCommandWebGL.PerformBuild 
     
  6. unityruba

    unityruba

    Unity Technologies

    Joined:
    Nov 6, 2020
    Posts:
    278
    what was the content of your PerformBuild method?
     
  7. AdViventes

    AdViventes

    Joined:
    Dec 17, 2016
    Posts:
    11
    Basically, I don't have previous not-working code. Only this working code from my solution (link above):

    Code (CSharp):
    1. using UnityEditor;
    2. using System;
    3. using UnityEditor.Build;
    4. using UnityEditor.Build.Reporting;
    5. /// <summary>
    6. /// Command to build project outside of Unity Editor. Used in CI/CD process.
    7. /// </summary>
    8. public class BuildCommandWebGL
    9. {
    10.     private const string BUILD_PARAM_KEY_BUILD_PATH = "buildPath";
    11.     private const string BUILD_PARMA_KEY_IS_DEVELOPMENT_BUILD = "isDevelopmentBuild";
    12.     /// <summary>
    13.     /// Entry point for builds outside of Editor. Used in CI/CD process.
    14.     /// </summary>
    15.     public static void PerformBuild()
    16.     {
    17.         Console.WriteLine("Performing build state");
    18.         var res = EditorUserBuildSettings.SwitchActiveBuildTargetAsync(BuildTargetGroup.WebGL, BuildTarget.WebGL);
    19.         Console.WriteLine(res ? "Manually set EditorUserBuildSettings" : "Manually failed set EditorUserBuildSettings");
    20.         Console.WriteLine("Currently domain should be reloading...");
    21.         EditorApplication.delayCall += AfterDomainReload;
    22.     }
    23.  
    24.     private static void AfterDomainReload()
    25.     {
    26.         Console.WriteLine("Filling _buildPlayerOptions...");
    27.         var buildPlayerOptions = new BuildPlayerOptions();
    28.         buildPlayerOptions.target = BuildTarget.WebGL;
    29.         buildPlayerOptions.targetGroup = BuildTargetGroup.WebGL;
    30.         buildPlayerOptions.locationPathName = GetPrimaryInputParam(BUILD_PARAM_KEY_BUILD_PATH);
    31.         var isDevelopmentBuildString = GetInputParam(BUILD_PARMA_KEY_IS_DEVELOPMENT_BUILD, "true");
    32.         var isDevelopmentBuild = bool.Parse(isDevelopmentBuildString);
    33.         buildPlayerOptions.options = isDevelopmentBuild ? BuildOptions.Development : BuildOptions.None;
    34.         buildPlayerOptions.scenes = GetEditorTypeScenes();
    35.      
    36.         Console.WriteLine("Got everything setup. Now time to build...");
    37.         var buildReport = BuildPipeline.BuildPlayer(buildPlayerOptions);
    38.         if (buildReport.summary.result != BuildResult.Succeeded)
    39.         {
    40.             throw new BuildFailedException($"Build preparation ended with {buildReport.summary.result} status");
    41.         }
    42.         Console.WriteLine($"Done with build preparation.");
    43.         EditorApplication.delayCall += ExitEditor;
    44.     }
    45.     private static void ExitEditor()
    46.     {
    47.         Console.WriteLine($"Time to close editor...");
    48.         try
    49.         {
    50.             EditorApplication.Exit(0);
    51.         }
    52.         catch
    53.         {
    54.             Console.WriteLine($"Exception was caught, but idc...");
    55.         }
    56.     }
    57.  
    58.     private static string GetInputParam(string paramKey, string defaultValue = "")
    59.     {
    60.         var inputParams = Environment.GetCommandLineArgs();
    61.         for (var i = 0; i < inputParams.Length; i++)
    62.         {
    63.             if (inputParams[i].Contains(paramKey))
    64.             {
    65.                 return inputParams[i + 1];
    66.             }
    67.         }
    68.         return defaultValue;
    69.     }
    70.     private static string GetPrimaryInputParam(string paramKey)
    71.     {
    72.         var paramValue = GetInputParam(paramKey);
    73.         if (string.IsNullOrEmpty(paramValue))
    74.         {
    75.             throw new BuildFailedException($"Param with key {paramKey} is missing");
    76.         }
    77.         Console.WriteLine($"Received input param. Key: {paramKey}, Value: {paramValue}");
    78.         return paramValue;
    79.     }
    80.     // Warning: Hardcoded names of scenes.
    81.     private static string[] GetEditorTypeScenes()
    82.     {
    83.         return new[]
    84.         {
    85.             "Assets/Scenes/SCENE.unity",
    86.             "Assets/Scenes/Debug/SCENE.unity"
    87.         };
    88.     }
    89. }
    As you can see I made a work-around using EditorApplication.delayCall. Also CLI param -quit doesn't work with it, so I manually exit Editor with EditorApplication.Exit(0)

    My previous not-working code looked something like this (I removed EditorApplication.delayCall methods):
    Also with this code I was adding param -quit to CLI line. And was using WebGLInput in my Scripts folder too.

    Code (CSharp):
    1. using UnityEditor;
    2. using System;
    3. using UnityEditor.Build;
    4. using UnityEditor.Build.Reporting;
    5. /// <summary>
    6. /// Command to build project outside of Unity Editor. Used in CI/CD process.
    7. /// </summary>
    8. public class BuildCommandWebGL
    9. {
    10.     private const string BUILD_PARAM_KEY_BUILD_PATH = "buildPath";
    11.     private const string BUILD_PARMA_KEY_IS_DEVELOPMENT_BUILD = "isDevelopmentBuild";
    12.     /// <summary>
    13.     /// Entry point for builds outside of Editor. Used in CI/CD process.
    14.     /// </summary>
    15.     public static void PerformBuild()
    16.     {
    17.         Console.WriteLine("Performing build state");
    18.         var res = EditorUserBuildSettings.SwitchActiveBuildTargetAsync(BuildTargetGroup.WebGL, BuildTarget.WebGL);
    19.         Console.WriteLine(res ? "Manually set EditorUserBuildSettings" : "Manually failed set EditorUserBuildSettings");
    20.         Console.WriteLine("Currently domain should be reloading...");
    21.      
    22.         Console.WriteLine("Filling _buildPlayerOptions...");
    23.         var buildPlayerOptions = new BuildPlayerOptions();
    24.         buildPlayerOptions.target = BuildTarget.WebGL;
    25.         buildPlayerOptions.targetGroup = BuildTargetGroup.WebGL;
    26.         buildPlayerOptions.locationPathName = GetPrimaryInputParam(BUILD_PARAM_KEY_BUILD_PATH);
    27.         var isDevelopmentBuildString = GetInputParam(BUILD_PARMA_KEY_IS_DEVELOPMENT_BUILD, "true");
    28.         var isDevelopmentBuild = bool.Parse(isDevelopmentBuildString);
    29.         buildPlayerOptions.options = isDevelopmentBuild ? BuildOptions.Development : BuildOptions.None;
    30.         buildPlayerOptions.scenes = GetEditorTypeScenes();
    31.      
    32.         Console.WriteLine("Got everything setup. Now time to build...");
    33.         var buildReport = BuildPipeline.BuildPlayer(buildPlayerOptions);
    34.         if (buildReport.summary.result != BuildResult.Succeeded)
    35.         {
    36.             throw new BuildFailedException($"Build preparation ended with {buildReport.summary.result} status");
    37.         }
    38.         Console.WriteLine($"Done with build preparation.");
    39.     }
    40.  
    41.     private static string GetInputParam(string paramKey, string defaultValue = "")
    42.     {
    43.         var inputParams = Environment.GetCommandLineArgs();
    44.         for (var i = 0; i < inputParams.Length; i++)
    45.         {
    46.             if (inputParams[i].Contains(paramKey))
    47.             {
    48.                 return inputParams[i + 1];
    49.             }
    50.         }
    51.         return defaultValue;
    52.     }
    53.     private static string GetPrimaryInputParam(string paramKey)
    54.     {
    55.         var paramValue = GetInputParam(paramKey);
    56.         if (string.IsNullOrEmpty(paramValue))
    57.         {
    58.             throw new BuildFailedException($"Param with key {paramKey} is missing");
    59.         }
    60.         Console.WriteLine($"Received input param. Key: {paramKey}, Value: {paramValue}");
    61.         return paramValue;
    62.     }
    63.     // Warning: Hardcoded names of scenes.
    64.     private static string[] GetEditorTypeScenes()
    65.     {
    66.         return new[]
    67.         {
    68.             "Assets/Scenes/SCENE.unity",
    69.             "Assets/Scenes/Debug/SCENE.unity"
    70.         };
    71.     }
    72. }
    If EditorApplication.delayCall wasn't used, then I've got same error as in this thread.
    I think, the problem was in scripting symbols. As stated in BuildPipeline docs:
    So I had to manually reload domain from CLI. If you have better solution, then I am all ears
     
    KeigoTakamura likes this.