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?)
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.
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
Here, you will find two files : UnityLoader.js and UnityLoader.min.js
Based on the previous answers, remove the JS code responsible for popping up the warnings and each time you will build for WebGL the previous files (now, without the warning) will be copied to the final build.
Cheers.
This worked for me in 2019.3.0a3. Don't forget to not only patch UnityLoader.js but also re-minify this file to UnityLoader.min.js There are plenty online minifiers but not all did work for me, this one did: https://skalman.github.io/UglifyJS-online/
I tried the solutions of @kart_ranger , @kleber-swf , @Skylabs and @TheRoccoB . They all made sense to me, but none of them worked. Is it possible that Unity added something that is actually calling for the warning message via an HTTP URL request?[132526-unityloader.txt|132526]
EDIT: I added my UnityLoader from my latest attempt. Changed the extension to .txt as this message board doesn’t allow .js attachments.
I switched out the functions because otherwise OnBeforeSerialize() will mostly be called even when you dont edit anymore which is resource consoming. The bool makes sure it will be called on the first time unity serialized this property, so this acts like a default value for single class fields like Test testInt above. If you leave the bool out, it will be resetted back to 500 everytime you want to reassign the value in the inspector.
2_ Open and copy all the content of these scripts:
UnityLoader.js
UnityLoader.min.js
and paste in a txt document.
3_ Comment or delete code lines…
var UnityLoader = UnityLoader || {
/*compatibilityCheck: function (gameInstance, onsuccess, onerror) {
if (!UnityLoader.SystemInfo.hasWebGL) {
gameInstance.popup("Your browser does not support WebGL",
[{text: "OK", callback: onerror}]);
} else if (UnityLoader.SystemInfo.mobile) {
gameInstance.popup("Please note that Unity WebGL is not currently supported on mobiles. Press OK if you wish to continue anyway.",
[{text: "OK", callback: onsuccess}]);
} else if (["Edge", "Firefox", "Chrome", "Safari"].indexOf(UnityLoader.SystemInfo.browser) == -1) {
gameInstance.popup("Please note that your browser is not currently supported for this Unity WebGL content. Press OK if you wish to continue anyway.",
[{text: "OK", callback: onsuccess}]);
} else {
onsuccess();
}*/
t();
},
Blobs: {},
Sorry for my English. It works in unity 2017.2.1f1.
Thank you all for helping to resolve this issue.
This is the best answer when you are dealing with more complex data like arrays and classes, I don't even know why I didn't think of this. Just parsing it to and from JSON with JsonUtility.
<script>
UnityLoader.compatibilityCheck = function (e, t) {t();}; // <== add this line
var unityInstance = UnityLoader.instantiate("unityContainer", "Build/WebOut.json", {onProgress: UnityProgress});
</script>
If you are using MD5 hashes the script can’t find Build/UnityLoader.js. So this adjustment will just take the first .js file which should be the the UnityLoader.
using System.IO;
using System.Linq;
using UnityEditor;
using UnityEditor.Callbacks;
// Disable mobile warning on webgl!
// https://answers.unity.com/questions/1339261/unity-webgl-disable-mobile-warning.html
public class PostBuildActions
{
[PostProcessBuild]
public static void OnPostProcessBuild(BuildTarget target, string targetPath)
{
string path;
if (File.Exists(Path.Combine(targetPath, "Build/UnityLoader.js")))
{
path = Path.Combine(targetPath, "Build/UnityLoader.js");
}
else
{
// In case files are hashed using MD5, just take the first .js file and hope it's the UnityLoader
var files = Directory.GetFiles(Path.Combine(targetPath, "Build/"), "*.js");
path = files.First();
}
var text = File.ReadAllText(path);
text = text.Replace("UnityLoader.SystemInfo.mobile", "false");
File.WriteAllText(path, text);
}
}
I still have some old projects on 2021.3.15f1. In index.html I edited unityShowBanner(‘…’); text to keep the warning but add a clarifier that the game may still run. I assume you can just comment out that line so no warning shows up, but I haven’t tried it yet.
I'm using the 2018 version and just saw this message (newbie). What should I do with this code?
– dfarjoun@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 ? :-)
– SkylabsAnd 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!
– kleber-swfIn 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?)
– janoonkFor Unity 2019 replace: [PostProcessBuild] with: [PostProcessBuildAttribute(1)] It works for me, I'm in v2019.3.0a3. Cheers!
– Patomanriquezb