0
\$\begingroup\$

After creating a release build of my game using Unity 5.6, I could navigate to the created folder and open the 'index.html' file and my game would load and play normally. However, when trying to integrate it into my WebApp (.NETCore 1.1), I would continually get this error in Chrome, Firefox, IE, etc..:

UnityLoader.js - SyntaxError: expected expression, got end of script

Invoking error handler due to TypeError: UnityLoader[r] is not a function

\$\endgroup\$
1
\$\begingroup\$

I thought I would share my resolution with you here.

I tried a variety of things, including lengthy web.config changes per recommendations on Unity's site, and others found in other forums, but the only thing I ended up needing to add was the following code to my Startup.cs file in the Configure() method:

StaticFileOptions option = new StaticFileOptions();
FileExtensionContentTypeProvider contentTypeProvider = (FileExtensionContentTypeProvider)option.ContentTypeProvider ??
new FileExtensionContentTypeProvider();
contentTypeProvider.Mappings.Add(".unityweb", "application/octet-stream");
option.ContentTypeProvider = contentTypeProvider;
app.UseStaticFiles(option);

The main point being that files with the extension ".unityweb" were located in my \Build folder and were the ones being used, despite the option being selected to use Gzip compression. Once built I never ended up with any *.unity3dgz file extensions. However, if your release does contain files with those extensions, you might want to try adding another Mapping for that, for example:

contentTypeProvider.Mappings.Add(".unity3dgz", "application/octet-stream");
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.