Every time i make a new player build i have to go into my splash screen and manually change the UI text to match my build number.
Can i just get the build number from a script?
Every time i make a new player build i have to go into my splash screen and manually change the UI text to match my build number.
Can i just get the build number from a script?
Yes.
Are you looking for Application.version?
Thank you. I have that, and it helps a lot. but im looking for the build number - see the attached
This is what im using, i get the application and unity version via script, but i have to type in the build number by hand into my script every export.
bn = Application.version+"b"+buildNumber+"e"+Application.unityVersion;
versionText.text = bn;
Thank you.
Unfortunately this only works in the Unity editor, not the build.
It’s not possible after all to get the build number inside the built app.
Ill keep typing it in manually. It’s not difficult, but it would be nice to save that extra step.
Copy the build number from the playersettings into a file as a pre or post build step.
Thank you:)
That is basically the same thing as just typing it into the script. OP was just being nice but truthfully this isn’t any help at all.
My solution for this was having a custome build script that did write the build version into a public variable in a scene before building the application.
Another way might be using a build post process to wirte a version / build file into the streaming assets folder.
How so? One is a manual step, one is a script that does it for you, which is what he was asking for.
Something like the example on this docs page: https://docs.unity3d.com/ScriptReference/BuildPipeline.BuildPlayer.html
2019.3.06f allows that. Add
using UnityEditor; to gain access to PlayerSettings.
Add public Text boxes to your class and add UI elements for display.
public Text bundleText;
public Text versionText;
Then in Start() use
versionText.text = "Version: " + Application.version.ToString();
bundleText.text = "Build: " + PlayerSettings.Android.bundleVersionCode.ToString();
NOTE: Works for Windows. Didn’t work for Android.
I created a build version based on the date/time at the time of build using reflection, similar to this:
http://luminaryapps.com/blog/showing-the-build-date-in-a-unity-app/
Doesn’t work for iOS either… this is really unfortunate…
UnityEditor doesn’t get included in builds, so this won’t work as-is.
+1 to just using a scriptable object to store the app version / build number in a pre-build step. That was super helpful and solved this problem quickly for me.
@xLeo can you elaborate on h ow to create the scriptable object?
I’ve never worked with them, so I did something like this:
public void OnPreprocessBuild(BuildReport report)
{
Debug.Log("MyCustomBuildProcessor.OnPreprocessBuild for target ");
IncrementBuild();
BuildState.BuildVersion = PlayerSettings.bundleVersion;
}
where BuildState is
public class BuildState : ScriptableObject
{
public static string BuildVersion;
public string Build2;
}
I think I have to get a reference to the scriptableobject I created in the assets folder, but I’m not sure how to do that from the editor (Resources.Load returns null, and I think I expect it to)
I have attached 2 stripped-down classes that we use.
Hope it helps!
6009920–647588–PlotBuildSettings.cs (2.64 KB)
6009920–647591–PlotBuildTools.cs (1.96 KB)
I get the error “The type or namespace name ‘Build’ does not exist in the namespace ‘UnityEditor’ (are you missing an assembly reference?)”
It’s complaining about this line “using UnityEditor.Build;”
It only happens when building and I don’t know why.
Target = Android, Unity 2020.2.1f1