Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
1
Question by TheSkrypt · Dec 15, 2015 at 12:50 AM · c#builddatapersistencedatapath

Saving build number to a file inside build data folder

Hello,

I hope I've posted this in the right section and all, I'm new to this Unity Answers Thing, so forgive me any mistakes I could have done. :-)

But now to my problem, I've been stuck with this a couple days now, but I just can't get it to work. So basically, I want to, whenever I build my game, to increment a variable containing information about the version of the product and the current build number, save a binary file containing that information INTO the GAME DATA folder (not %appdata% or anything, but pack it right withing the game itself) and then anytime the game is played (!Application.isEditor), load that file, deserialize it, get the build and print it onto an UI, so the user knows exactly which version and build he is using.

Saving and loading works and incrementing the build number and all that stuff, the problem comes now - when I have to decide how and where to save the file.

I've found method of return type string called Application.dataPath, which gives me the path to the data folder. When I print this while inside the editor, this gives me the path to Assets/ folder. So I thought I've suceeded now.

But when the game is build, that assets folder gets packed into various files and folders and I have no idea where it at the end lands. When I print this Application.dataPath string while playing the built .exe though, it leads to the folder next to my .exe called _Data, but this one doesn't contain the files from Assets/, so even my file that contained the build number and version is gone. It exists, but it is somewhere packed inside the .assets files or something like that.

Anyone got some idea how I could fix this? Or even a complete different, better way of implementing such build and version tracking?

Thanks in advance, Skrypt

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
1
Best Answer

Answer by TheSkrypt · Dec 14, 2015 at 08:53 PM

After 7 hours of trying, I finally found out on my own.

For anyone who has the same problem, here is how I proceeded:

I've created a script that handles saving / loading data and assigned it to a gameobject. This script has also the build number variable assigned. And using Singleton it is added in each scene and only one at a time. On the Start() Method I create a file with the build number set to 1.

Next, I created an editorScript with an PostProcessBuildAttribute assigned to a function, that gets the final builded project data folder. Into that folder I create a a new file with the data, that I load from the previously saved file inside the assets folder, incremented by 1. And save both files. That way, anytime I build the project, it gets the the value from the version info file in the assets, increment it by 1 and save the new incremented value into both files, one inside the assets for later use and one pasted directly inside the final game data folder.

Anytime I now want to access this build value, I use Application.dataPath to get access to the data folder, if run in editor this will be assets, if run standalone this will be _Data. Then just read the file, deserialize it (if you save it as binary files) and print the content whereever you want.

I hope this makes the whole thing clear, if not, feel free to spam me with any questions you might have about this, I will be more than happy to try and help you as best as I can. :-)

regards, Skrypt

Comment
Add comment · 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
0

Answer by Dave-Carlile · Dec 15, 2015 at 12:53 AM

You don't need to do all of that...

This may only work if you're using Visual Studio, but you can use the AssemblyVersion attribute and you'll get auto-incrementing version information that you can extract directly from the assembly.

 using System.Reflection;
 
 [assembly: AssemblyVersion("0.1.*")]
 public class AssetManager
 {
     static string version = null;
 
     public static string GetVersion()
     {
         if (version == null)
         {
             try
             {
                 version = Assembly.GetExecutingAssembly().GetName().Version.ToString();
             }
             catch
             {
                 version = "Unknown";
             }
         }
 
         return version;
     }
 }

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 TheSkrypt · Dec 15, 2015 at 06:49 AM 0
Share

Thanks for the reply, but I know about this way. The thing I don't like is, you are limited to the assembly kind versioning, x.x.x, I want to be able to have own versioning + this time I especially just wanted the current Buildnumber, but not version. The way posted above in the comment by me works perfectly though. :)

avatar image Dave-Carlile TheSkrypt · Dec 15, 2015 at 01:04 PM 0
Share

Not a problem. Go ahead and convert your comment to an answer and mark it as accepted so the question is closed out. It's kind of an interesting way to get customized data into a build and may be useful to someone searching.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Distribute terrain in zones 3 Answers

Most convenient and fast way to persist/access/modify many values from scene to scene? (C#) 0 Answers

Persistence of saving data not working 2 Answers

Executing Code by Scenes 1 Answer

Multiple Cars not working 1 Answer


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