- Home /
Difference between Application.version and PlayerSettings.bundleVersion
I want to auto-increment the version number that appears as "App Version" in Unity Cloud Diagnostics every time I make a new PC build. I assume this is Application.version.
Application.version is read-only and can only be edited via Edit>Project Settings>Player>Version.
Enter PlayerSettings.bundleVersion. This field CAN be edited in code, and when I do (at least in the local editor on PC) it changes both Application.version and Edit>Project Settings>Player>Version. The docs say it is only used for Android and iOS builds (I have neither package and only care about PC).
So: is one just a reference to the other? Will they ever differ? Is it OK to use PlayerSettings.bundleVersion for a PC build? As usual the docs aren't helpful.
Answer by darbotron · Sep 08, 2020 at 08:31 AM
We use PlayerSettings.bundleVersion (accessible only in editor) to set Application.version (also accessible in the player) for all platforms & we don't do mobile games we do PC / consoles...
(@sarahnorthway I assume you've worked this out by now :) )
I guess we're both doing the right thing. It makes sense for version to be read-only in the player, but the way it's set up (and not documented) is confusing af. For posterity, my class which auto-increments build version after each build:
using UnityEngine;
using UnityEditor;
using UnityEditor.Callbacks;
/// <summary>
/// Automatically increment InternalSettingsInstance.versionBuild after an EXE is built.
/// </summary>
public class BuildPostprocessor {
[PostProcessBuildAttribute(1)]
public static void OnPostprocessBuild(BuildTarget target, string pathToBuiltProject) {
// to update major or $$anonymous$$or version, manually set it in Edit>Project Settings>Player>Other Settings>Version
// this will also set Application.version which is readonly
string[] versionParts = PlayerSettings.bundleVersion.Split('.');
if (versionParts.Length != 3 || versionParts[2].ParseInt(-1) == -1) {
Debug.LogError("BuildPostprocessor failed to update version " + PlayerSettings.bundleVersion);
return;
}
// major-$$anonymous$$or-build
versionParts[2] = (versionParts[2].ParseInt() + 1).ToString();
PlayerSettings.bundleVersion = versionParts.Join(".");
}
}
Here's another approach to almost the same thing (from https://twitter.com/martinpi/status/1309490503591886850)
If this gist set PlayerSettings.bundleVersion rather than PlayerSettings.iOS.buildNumber it would be the same as @sarahnorthway's but done before the exe is built. https://gist.github.com/martinpi/f4311512c443b8134bda3f268ae7abd3
Everything in the answers above is still correct in 2021.3.4f1 -- I'll just add that changes to PlayerSettings.bundleVersion
do not save if you are in Play mode, but are persistent if made in an editor script (including at build time). Writing to PlayerSettings.bundleVersion
immediately changes the output of Application.version
.