Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by c.ovayurt · Apr 20, 2015 at 06:53 AM · unity 5javascriptversionbundle

Unity 5 PlayerSettings.bundleVersion unknown identifier : 'PlayerSettings' javascript-C#

Hello everyone,

I need to get the bundle version of the game in runtime. PlayerSettings.bundleVersion works good in unity editor but when building for Android, it says unknown identifier : 'PlayerSettings' .I watn to get the bundle version code in runtime. How can i make it work ?

Well i tried something like platform dependent compilation but it didn't work either. It was like :

     #if UNITY_EDITOR
        Debug.Log(PlayerSettings.bundleVersion);
     #endif
     #if UNITY_ANDROID
        Debug.Log(PlayerSettings.Android.bundleVersion);
     #endif


PlayerSettings in UNITY_EDITOR tags works good but PlayerSettings in UNITY_ANDROID tags gives same error, unknown identifier.

Thanks in advance.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
3

Answer by NicoL3AS · May 05, 2016 at 05:02 AM

Hi guys, I may have a more elegant solution:

0 - Let's assume you want to access the bundleVersion in a script named MyAwesomeScript, attached to the GameObject named MyBeautifulObject.

1 - Create a C# script called RuntimePlayerSettings with the following code:

 using UnityEngine;
 
 #if UNITY_EDITOR
 using UnityEditor;
 #endif
 
 [ExecuteInEditMode]
 public class RuntimePlayerSettings : MonoBehaviour
 {
 
     public string bundleVersion;
 
     #if UNITY_EDITOR
     void Update () {
         bundleVersion = PlayerSettings.bundleVersion;
     }
     #endif
 
 }

2 - Attach this RuntimePlayerSettings script to MyBeautifulObject.

3 - In MyAwesomeScript, you can get the bundleVersion like that :

 string version = gameObject.GetComponent<RuntimePlayerSettings>().bundleVersion;

It should works on all platforms (editor included) and, for devices, it will get the last bundleVersion entered before compiling.

Of course, it does not work only for bundleVersion. You can add as many static variables of PlayerSettings as you want to RuntimePlayerSettings.

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image guneyozsan · May 16, 2017 at 11:24 PM 0
Share

Works great. Can you explain why this works?

avatar image NicoL3AS guneyozsan · May 17, 2017 at 11:46 AM 0
Share

Unity uses scripts in 2 ways: in the editor and in the running game. Problem is: "PlayerSettings.bundleVersion" is not accessible in the running game, only in the editor. Fortunately, scripts parameters (like the string "bundleVersion" you can see in my example) are both accessible from the editor and from the game. So with this script, in the editor, each time the bundle version is updated, I update the parameter "bundleVersion" with the value of "PlayerSettings.bundleVersion". So when the game is exported, it automatically export the last bundle version stored in the script parameter. Not sure I am clear enough. Do you get it?

avatar image guneyozsan NicoL3AS · May 17, 2017 at 01:13 PM 0
Share

Thank you for the explanation. At first I wasn't able to understand how a variable in memory is carried from editor to the build. After your comment I realized that the string bundleVersion is serialized and updating its initial value in the editor makes it available in the build as well. Very elegant solution, thanks.

avatar image
0

Answer by furic · Apr 20, 2015 at 08:38 AM

PlayerSetting is in UnityEditor, that means like all other Editor scripts they are not imported when building the game.

So running PlayerSettings.Android.bundleVersion in Android will give you a NullException.

A simple but stupid solution, create your own constant and change it every time you build.

 public const string VERSION = "0.9.2"; // Change this to build version everytime create a build!


Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image c.ovayurt · Apr 20, 2015 at 10:07 AM 0
Share

That is not the answer. This way is not eligible. I need the version code in runtime. Thank you for your answer.

avatar image furic · May 12, 2015 at 05:01 AM 0
Share

i don't see why u can't do this this way. you are like asking for a function not in Unity

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

22 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Help with attacking, and death animation. Unity 5 javascript 1 Answer

Variable Not Changing. 0 Answers

This not reading folders in the Windows Store 0 Answers

WWW.url ERROR:This site requires Javascript to work, please enable Javascript in your browser or use a browser with Javascript support 2 Answers

Cant get Monodevolop to work 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges