Search Unity

How to modify WebGL template JS macros from script

Discussion in 'Web' started by ninipols, Dec 15, 2020.

  1. ninipols

    ninipols

    Joined:
    May 28, 2016
    Posts:
    2
    Hey y'all, I'm currently working on a build tool that automatically creates multiple WebGL builds with different player settings. I'm doing this in 2020.1 and I know that 2020.1 introduced the ability to use custom javascript macros in WebGL templates. Is it possible to modify the values of these macros from script (like a C# build script or something) or elsewhere? I'm asking because it would be cumbersome to have to change them manually in the player settings.

    @jukka_j
     
    DerrickBarra likes this.
  2. doctorpangloss

    doctorpangloss

    Joined:
    Feb 20, 2013
    Posts:
    270
    You can modify player settings variables, indeed everything you could typically modify in the Editor, from an Editor script. Try using Rider and poking about the assemblies to find the methods you need.
     
  3. Xorboo

    Xorboo

    Joined:
    Dec 6, 2014
    Posts:
    6
    Sorry for necroposting, but I haven't found an answer to this in any of the threads, so decided to share the solution after some digging.

    To set it from script you should use
    PlayerSettings.SetTemplateCustomValue()
    method, which is for some reason not in the
    PlayerSettings.WebGL
    group (which is why it may be hard to find).

    1. Note that the docs now call it Custom user variables, they don't require
      UNITY_CUSTOM_
      prefix anymore, and are using
      {{{ triple brackets }}}
      instead of
      %percentage%
      wrappers
    2. They are also quite buggy to update, either not appearing in the settings or clearing up after input - restarting Unity and running a build fixed that for me
    3. Doing this on 2021.3
     
    dm_bond and Marks4 like this.