superunitybuild / buildtool

A powerful automation tool for quickly and easily generating builds with Unity.
MIT License
1.19k stars 121 forks source link

Customize build constants #78

Closed wilg closed 2 years ago

wilg commented 2 years ago

It appears not to be possible to customize build constants without editing the source, is that correct? Would be very handy to add other things. In my case, I want to set a deterministic build number derived from the Git commit count, and the current Git commit SHA.

robinnorth commented 2 years ago

It's not possible to add additional build constants without editing the source, that is correct.

The use case you describe sounds like the sort of thing you could achieve with a pre-build action, in the same way that the OverrideDefines build action gives you additional control over build defines. Try having a look at the source of that action as a starting point for writing your own.

Hope this helps!

wilg commented 2 years ago

OK, I sort of copied the existing build constants thing to a new "ExtraBuildConstants" which works fine.

But what about setting the build number from code? Is there a good place to do that? Doesn't seem like I can do it in the pre-build action.

wilg commented 2 years ago

I added this to my pre-build script, deselected "Auto Generate Version" and selected "Sync Version With Player Settings":

        PlayerSettings.Android.bundleVersionCode = commitCountInt;
        PlayerSettings.iOS.buildNumber = commitCount;
        PlayerSettings.macOS.buildNumber = commitCount;
        PlayerSettings.bundleVersion = $"1.0.{commitCount}";

It seems to work sometimes but it seems to sometimes not update the build number before building (so I get the previous build number). (i.e. I have to hit "Configure Editor Environment" twice)

robinnorth commented 2 years ago

That sounds like the right approach to me. Have you checked to see if your build action is run every time you build/use 'Configure Editor Environment' to determine if the reason you're only seeing the version updated sometimes is because the action doesn't always run, or because your commit count number doesn't always get updated?