Search code examples
unity-game-engineunity-webgl

Can not build WebGL in Unity


I'm trying to build my unity project in WebGL, but it keeps giving me an error. the build result says it succeeded but in the folder, there's nothing.

here is the error that i got.

FileNotFoundException: Could not find file "C:\Users\TIGER\Desktop\UnityTest\Prototype3\Temp\StagingArea\Data\Native\build.bc" System.IO.FileStream..ctor (System.String path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share, System.Int32 bufferSize, System.Boolean anonymous, System.IO.FileOptions options) (at :0) System.IO.FileStream..ctor (System.String path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share) (at :0) (wrapper remoting-invoke-with-check) System.IO.FileStream..ctor(string,System.IO.FileMode,System.IO.FileAccess,System.IO.FileShare) System.IO.File.OpenRead (System.String path) (at :0) System.IO.File.ReadAllBytes (System.String path) (at :0) UnityEditor.WebGL.WebGlBuildPostprocessor.LinkBuild (UnityEditor.Modules.BuildPostProcessArgs args) (at /Users/builduser/buildslave/unity/build/PlatformDependent/WebGL/Extensions/Unity.WebGL.extensions/BuildPostprocessor.cs:464) UnityEditor.WebGL.WebGlBuildPostprocessor.PostProcess (UnityEditor.Modules.BuildPostProcessArgs args) (at /Users/builduser/buildslave/unity/build/PlatformDependent/WebGL/Extensions/Unity.WebGL.extensions/BuildPostprocessor.cs:954) UnityEditor.Modules.DefaultBuildPostprocessor.PostProcess (UnityEditor.Modules.BuildPostProcessArgs args, UnityEditor.BuildProperties& outProperties) (at C:/buildslave/unity/build/Editor/Mono/Modules/DefaultBuildPostprocessor.cs:27) UnityEditor.PostprocessBuildPlayer.Postprocess (UnityEditor.BuildTargetGroup targetGroup, UnityEditor.BuildTarget target, System.String installPath, System.String companyName, System.String productName, System.Int32 width, System.Int32 height, UnityEditor.BuildOptions options, UnityEditor.RuntimeClassRegistry usedClassRegistry, UnityEditor.Build.Reporting.BuildReport report) (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/PostprocessBuildPlayer.cs:286) UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr) (at C:/buildslave/unity/build/Modules/IMGUI/GUIUtility.cs:179)


Solution

  • You can't access local file system when using unity webgl. If there is any csharp file that handling System.IO functionality then, place them under this check and build.

        #If !UNITY_WEBGL
        #endif