PlayerSettings.WebGL.template need revamp

Hello Unity dev,
I was trying to use your PlayerSettings.WebGL.template and to do so, I basically just read the documentation from your website :

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

IndexOutOfRangeException: Index was outside the bounds of the array.
UnityEditor.WebGL.WebGlBuildPostprocessor.PostProcess (UnityEditor.Modules.BuildPostProcessArgs args) (at /Users/builduser/buildslave/unity/build/PlatformDependent/WebGL/Extensions/Unity.WebGL.extensions/BuildPostprocessor.cs:936)
UnityEditor.Modules.DefaultBuildPostprocessor.PostProcess (UnityEditor.Modules.BuildPostProcessArgs args, UnityEditor.BuildProperties& outProperties) (at C:/buildslave/unity/build/Editor/Mono/Modules/DefaultBuildPostprocessor.cs:27)
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)
UnityEditor.BuildPipeline:BuildPlayer(BuildPlayerOptions)
ChangeTemplateBuild:ChangeTemplateOnBuild() (at Assets/Scripts/Editor/ChangeTemplateBuild.cs:20)

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

APPLICATION:UnityTemplateName

and when it’s user based template it’s

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.

3 Likes

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 ?

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?

@SashaKC I’ll do it on monday morning when I’m back to the office :wink:

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:

PlayerSettings.WebGL.template = "PROJECT:UserTemplateName";
2 Likes

Glad you finally find it !
Yeah it’s clearly not userfriendly or explained anywhere :confused:

I will post my code but if you find it it’s nice :smile:

also running into this issue - selection manually from project settings gives the same failure
case 1254077