Unity WebGL Disable mobile warning
Hi,
I would like to disable the default warning: "Please note that Unity WebGL is not currently supported on mobiles."
Does anyone know if it's possible?
In the Unity Forums the user "jonas-echterhoff" wrote that you could deactivate the message. https://forum.unity3d.com/threads/webgl-for-mobile-devices.291068/#post-1921583
Thanks and have a nice day, Jordan Kniest
Answer by Skylabs · Oct 11, 2018 at 01:44 PM
Hi here is a new version that is working with the 2018 version :-)
using System;
using System.IO;
using System.Text.RegularExpressions;
using UnityEditor;
using UnityEditor.Callbacks;
public class PostBuildActions
{
[PostProcessBuild]
public static void OnPostProcessBuild(BuildTarget target, string targetPath)
{
var path = Path.Combine(targetPath, "Build/UnityLoader.js");
var text = File.ReadAllText(path);
text = text.Replace("UnityLoader.SystemInfo.mobile", "false");
File.WriteAllText(path, text);
}
}
I'm using the 2018 version and just saw this message (newbie). What should I do with this code?
@kleber-swf explained it good in his post :
Just create a file PostBuildActions.cs inside any Editor folder and execute your build normally. It will replace the problematic function with the proposed solution.
So create the file PostBuildActions and post the above code inside and normally when you will build your Webgl, no more mobile warning ! Right like that ? :-)
And if some of the questions helped you, help the community back and give them an up vote. This will make the life of the next people who look for the same answer easier. Cheers!
In Unity 2019.3.0a3 when WebGL Building I get an error: The type or namespace name 'Callbacks' does not exist in the namespace 'UnityEditor' (are you missing an assembly reference?)
For Unity 2019 replace: [PostProcessBuild]
with: [PostProcessBuildAttribute(1)]
It works for me, I'm in v2019.3.0a3.
Cheers!
I tried that but I get the same error when building for WebGL.This is my PostProcessBuildScript.cs
using UnityEngine;
using UnityEditor;
using UnityEditor.Callbacks;
public class PostProcessBuildScript
{
[PostProcessBuildAttribute(1)]
public static void OnPostprocessBuild(BuildTarget target, string pathToBuiltProject)
{
Debug.Log("Called from OnPostprocessBuild: "+pathToBuiltProject);
}
}
I think I know what's the problem. This particular script needs to be inside a folder named Editor, it can be anywhere in your project, but it has to have that name. The thing is, this script is not supposed to be built into your WebGL app, it only modifies the building process, so you HAVE to put it in that folder so Unity can know that.
Where can i get PostProcessBuildAttribute script ? Thanks
Answer by kart_ranger · Sep 24, 2017 at 01:00 AM
To understand what exactly goes with the js script, format it first, mine was completely not formatted. I used this jsbeautifier.org. Anyways, all you have to do is the following to by pass the warning. For your clarity i'm attaching my UnityLoader.js as well.
compatibilityCheck: function(e, t, r) {
t();
},
[1]: /storage/temp/102465-unityloader.zip
Can confirm, this works for 2019 version of Unity aswell. Thank you!
Answer by kleber-swf · Mar 09, 2018 at 09:45 PM
Based on @kart_ranger 's answer, I made a small class to handle it automatically after the build is done:
using System;
using System.IO;
using System.Text.RegularExpressions;
using UnityEditor;
using UnityEditor.Callbacks;
public class PostBuildActions {
[PostProcessBuild]
public static void OnPostProcessBuild(BuildTarget target, string targetPath) {
var path = Path.Combine(targetPath, "Build/UnityLoader.js");
var text = File.ReadAllText(path);
text = Regex.Replace(text, @"compatibilityCheck:function\(e,t,r\)\{.+,Blobs:\{\},loadCode",
"compatibilityCheck:function(e,t,r){t()},Blobs:{},loadCode");
File.WriteAllText(path, text);
}
}
Just create a file PostBuildActions.cs
inside any Editor folder and execute your build normally. It will replace the problematic function with the proposed solution.
Please keep in mind that this code could be incompatible with future versions of Unity WebGL build. It was tested on Unity Editor 2017.3.0f3
Answer by Schubkraft · Apr 13, 2017 at 08:07 AM
The message is part of the UnityLoader.js file and you can just edit that to whatever you want with a text editor.
It seems UnityLoader.js is generated each time - is there a way to have this mod be persistent?
See below for the PostProcess version or edit the original files under where Unity gets them for the builds.
Answer by nullgamestudio · Nov 26, 2019 at 08:42 PM
Hello everyone, this works for me in 2019.2.4 :
UnityLoader.compatibilityCheck=function(e,t,r){t();};
in the index.html file , right before the unityloader instantiate line.
Thank you so mucho!!! Work for me in Unity 2017.2.1f1
Thank you again.