Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Feedback PlayerSettings.WebGL.template need revamp

Discussion in 'WebGL' started by aurelien-morel-ubiant, Jan 21, 2020.

  1. aurelien-morel-ubiant

    aurelien-morel-ubiant

    Joined:
    Sep 27, 2017
    Posts:
    275
    Hello Unity dev,
    I was trying to use your
    Code (CSharp):
    1. PlayerSettings.WebGL.template
    and to do so, I basically just read the documentation from your website :

    https://docs.unity3d.com/ScriptReference/PlayerSettings.WebGL-template.html

    This documentation seems pretty clear by the way : Path to the WebGL template asset.

    So to patch this part during my automation process, I just read the WebGLTemplates folder and set this variable with the one I need.

    When I execute my straightforward code based on your documentation, my build failed with this message


    Code (CSharp):
    1. IndexOutOfRangeException: Index was outside the bounds of the array.
    2. UnityEditor.WebGL.WebGlBuildPostprocessor.PostProcess (UnityEditor.Modules.BuildPostProcessArgs args) (at /Users/builduser/buildslave/unity/build/PlatformDependent/WebGL/Extensions/Unity.WebGL.extensions/BuildPostprocessor.cs:936)
    3. UnityEditor.Modules.DefaultBuildPostprocessor.PostProcess (UnityEditor.Modules.BuildPostProcessArgs args, UnityEditor.BuildProperties& outProperties) (at C:/buildslave/unity/build/Editor/Mono/Modules/DefaultBuildPostprocessor.cs:27)
    4. UnityEditor.PostprocessBuildPlayer.Postprocess (UnityEditor.BuildTargetGroup targetGroup, UnityEditor.BuildTarget target, System.String installPath, System.String companyName, System.String productName, System.Int32 width, System.Int32 height, UnityEditor.BuildOptions options, UnityEditor.RuntimeClassRegistry usedClassRegistry, UnityEditor.Build.Reporting.BuildReport report) (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/PostprocessBuildPlayer.cs:286)
    5. UnityEditor.BuildPipeline:BuildPlayer(BuildPlayerOptions)
    6. ChangeTemplateBuild:ChangeTemplateOnBuild() (at Assets/Scripts/Editor/ChangeTemplateBuild.cs:20)
    7.  
    this message was odd to me. Why I obtained a index out of range ? In the documentation you only mentionned a string. I was sceptical.

    Then I debug the value you currently save in it and the result just blow my mind...
    When it's your template it's
    Code (CSharp):
    1. APPLICATION:UnityTemplateName
    and when it's user based template it's
    Code (CSharp):
    1. PROJECT:UserTemplateName
    So just please I have 3 requests :
    1. Could you update your documentation and change this "path" notion cause it's wrong. You can't call it a "path".
    2. Could you change your error message and just say syntax is incorrect instead of do all your process and fail. Maybe using a try catch or something like this could be a nice idea ?
    3. When it failed, Unity will select the first user custom template in the list which is quite odd too. When you have only one template, your user can think : Why does it fail because it selects the good one ?


    Thanks.
     
    xucian, DMorock and nfynt-zap like this.
  2. aurelien-morel-ubiant

    aurelien-morel-ubiant

    Joined:
    Sep 27, 2017
    Posts:
    275
    Just to be sure to be read by at least one unity dev on this point, sorry to ping you @Marco-Trivellato

    I can create a bug report too if it seems to be a better process ?
     
  3. SashaKC

    SashaKC

    Joined:
    Sep 28, 2018
    Posts:
    2
    I agree with what aurelien said.

    Also @aurelien-morel-ubiant did you manage to get this to work? Could you show a code sample of how exactly did you manage to set a WebGL template through code?
     
  4. aurelien-morel-ubiant

    aurelien-morel-ubiant

    Joined:
    Sep 27, 2017
    Posts:
    275
    @SashaKC I'll do it on monday morning when I'm back to the office ;)
     
  5. SashaKC

    SashaKC

    Joined:
    Sep 28, 2018
    Posts:
    2
    Thank you for the reply.

    I managed to get it to work. I wasn't aware that "PROJECT:UserTemplateName" is literally what is says, not the project path to the template.

    In case anyone else gets confused:

    Code (CSharp):
    1. PlayerSettings.WebGL.template = "PROJECT:UserTemplateName";
     
    DMorock and sama-van like this.
  6. aurelien-morel-ubiant

    aurelien-morel-ubiant

    Joined:
    Sep 27, 2017
    Posts:
    275
    Glad you finally find it !
    Yeah it's clearly not userfriendly or explained anywhere :/

    I will post my code but if you find it it's nice :D
     
  7. kalineh

    kalineh

    Joined:
    Dec 23, 2015
    Posts:
    240
    also running into this issue - selection manually from project settings gives the same failure
    case 1254077