- Home /
How do you save PlayerSettings.bundleVersion to a variable?
I'd like to print PlayerSettings.bundleVersion to the screen so I can display it on the screen as a build number. The problem is that PlayerSettings.bundleVersion is an editor only setting, so I need to take that value and set it to a variable that I can use in script. I believe I need to make an editor script to save off the value to be able to access it in a script. How do you save PlayerSettings.bundleVersion to a variable to use in script?
Answer by iwaldrop · May 02, 2013 at 02:28 PM
You could just have a static string in whatever script is responsible for printing debug info to the screen. In order to set it, simple use .ToString().
void SomeMethod
{
SomeScript.staticString = PlayerSettings.bundleVersion.ToString();
}
This works when playing in the editor, but the issue is when I build for iOS. I get an error because PlayerSettings is editor only, iOS doesn't recognize it:
Assets/Scripts/DebugPrint.js(17,22): BCE0005: $$anonymous$$ identifier: 'PlayerSettings'.
Is there a way to save off bundleVersion using an editor script that was I can access that variable from a regular script?
Well, that's what I just gave you. You save the value of bundleVeraion as a string in a monobehaviour.
But, of course you have to run that code from an editor script. I perhaps wrongly assumed you already were at that stage. :)
Static variables won't serialize, however, so you'll need a singleton instance (such as a main Game manager) with a non-static member to hold the version.
Your answer
Follow this Question
Related Questions
problem with the digits of my timer 1 Answer
Show prefab/GO in viewport via script 1 Answer
Detecting if the 2D Mode button was pressed 2 Answers
How can you modify the default script templates when creating a new script file on Mac 2 Answers
Instance of [Editor] couldn't be created because there is no script with that name. 1 Answer