0

When loading Unity WebGL exported project in UWP Webview, the actual game does not load. However, loading it from a localhost server works fine! I have tried loading project from Assets folder, local folder on the computer and from the server. First two does not work.

I have tried loading normal WebGL project in webview and it works fine. Unity export does not. Loading the project in Edge browser works fine. Can anyone suggest me the right way to go about?

2 Answers2

1

Answering my own question:

After debugging the Unity script, I found out that it was an issue with relative links to json file and dataURL. Thus, when coming from the server, the export worked but did not work when put in Assets folder.

The solution was to move the Unity export to the following location:

C:\Users\YOUR_USER_NAME\AppData\Local\Packages\UWP_APP_PACKGAGE_NAME\LocalState\UNITY_PROJECT_NAME

where, UWP_APP_PACKAGE_NAME can be found or set in the app's manifest file.

This location is accessed via webview method

<!-- Source file is in local storage. -->
<WebView x:Name="webView2" Source="ms-appdata:///local/UNITY_PROJECT_NAME/index.html"/>

It is sad that Unity Webgl does not run when source is inside app package. Hope this is fixed in the future.

0

UWP WebView control is support WebGL. Please try to use SeparateProcess mode WebView to replace the default one.

public MainPage()
{
    this.InitializeComponent();
    var MyWebView = new WebView(WebViewExecutionMode.SeparateProcess);
    MyWebView.Source = new Uri("http://cycleblob.com/");
    this.RootGrid.Children.Add(MyWebView);
}
Nico Zhu
  • 32,367
  • 2
  • 15
  • 36
  • Sorry this solution did not work. I tried debugging the unity script from inside Visual Studio and found that it had something to with Unity Webgl's dataURL and Build.json file. I found out the solution was to move the Unity export to LocalState folder of the app package and access it via ms-appdata method. – Saurav Bajracharya Jan 30 '19 at 06:14
  • By the way, if your solution solve the issue, you could mark yourself. – Nico Zhu Jan 30 '19 at 06:30