Search Unity

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

Discussion in 'Web' started by theonlybrien, May 27, 2017.

  1. theonlybrien

    theonlybrien

    Joined:
    Feb 9, 2015
    Posts:
    2
    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
    AND
    Invoking error handler due to
    TypeError: UnityLoader[r] is not a function

    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 <GameName>\Build folder.
     
  2. Schubkraft

    Schubkraft

    Unity Technologies

    Joined:
    Dec 3, 2012
    Posts:
    1,073
    Yes, the MIME type for the unityweb files need to be setup for you app/on your server.
     
  3. SteenPetersen

    SteenPetersen

    Joined:
    Mar 13, 2016
    Posts:
    104
    Its a bit frustrating to read these forums and try to find solutions for these issues. a sentence like this:

    "Yes, the MIME type for the unityweb files need to be setup for you app/on your server."

    assumes all readers know what a MIME type is, where its located, how to edit it etc. Its a sentence written as if its obvious, even though I would wager a majority of people finding this thread do not know how to do this. a little more detail would help a lot more.

    I am trying to upload my webgl game to my webhotel and getting same errors as the original poster, However I have no Startup.cs file and I dont even have a web.config that everyone is always mentioning. can someone please make a run down about what these things even are? If we can make our own files? if so how to do it? link your scripts if possible. where do we place it?
     
    meta_monkey and aliaksei_kalosha like this.
  4. Schubkraft

    Schubkraft

    Unity Technologies

    Joined:
    Dec 3, 2012
    Posts:
    1,073