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
4
Question by Bampf · Nov 30, 2009 at 02:14 AM · version-control

How can a game automatically display the date/time of when it was built, and/or an incremented revision string?

Sometimes it is useful for a game to display version information, or a revision number such as is assigned by version control or continuous integration solution. What's a good way to do this for a Unity game?

Comment
Add comment · Show 1
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 Bampf · Nov 30, 2009 at 02:16 AM 0
Share

Jaap $$anonymous$$reijkamp already has a solution for build-time; I'd like him to move that answer over here. But I'd also welcome solutions for embedding information such as the SubVersion revision.

7 Replies

· Add your reply
  • Sort: 
avatar image
6
Best Answer

Answer by jashan · Nov 30, 2009 at 10:18 AM

The usual way how this is done is by having keywords which are expanded by the version control on checkin. You can then use that keyword in a string in your game and simply display that.

Something like:

const string GAME_VERSION = "$Date: $"; // that's how it would be done with CVS

public void OnGUI() { GUI.Label(new Rect (10, 10, 100, 20), GAME_VERSION); }

Now, as far as I know, Asset Server doesn't have such keywords (that would be a feature-request ;-) ). Examples of keywords used by other version control systems:

  • CVS Keywords
  • SVN Keywords

Of course, you might want to be doing some string-cleanup to remove the "cryptic" parts of the version control keywords.

Personally, I prefer to use labels I manually assign for releases (you could do that in a property in one of your "core management" prefabs that you can easily change in the Unity editor and that is accessible from where ever you have the GUI code to display that information). Usually, that creates more meaningful information for actual users and seems like a small extra-step to take while creating my builds. However, using the automatic assignment of dates through version control might be helpful in "hot development" (when you push out releases every few days). Keep in mind, though: That value will only change when you actually made a change to that file.

Finally, there's yet another solution: If you have a custom build-system (which can be implemented Unity's batch mode features), you might do your own replacement in the code during the build; and you'd increase the number for each build (or include the build-date, or whichever information you find useful). You could also keep that number / text in a little text-file that your game-code can access (might be easier to set up than doing the string replacement in your code but adds a little complexity in your game-code).

In my opinion, that's the optimal solution (meaningful values + no manual work involved once it's set up + totally customizable) - but also the most complex one to set up. But when you know how to set up a build-system, that should be one of your smaller concerns ;-)

Comment
Add comment · Show 1 · 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 Ben 2 · Feb 04, 2010 at 09:21 PM 0
Share

I like the build system solution. A simple way to do that is to put some constants in a class (AppStuff.BUILD_DATE or whatever). Have those be empty string in your project code then use scripting to create the class with the constants' values and overwrite the class at build time. Then the rest of your code need only access the constant to display the right build date, version, or whatever info you desire.

avatar image
7

Answer by futurecrayon · Mar 21, 2015 at 04:31 PM

Here's a simple solution that uses the C# assembly version.

Specify the AssemblyVersion attribute like so:

 using System.Reflection;
 
 [assembly:AssemblyVersion( "1.0.*.*" )]
 
 public class MainMenu : MonoBehaviour {
 ...

And you can retrieve a formatted version number like so:

 print( Assembly.GetExecutingAssembly().GetName().Version.Tostring() );

This prints out the Version in Major.Minor.Build.Revision format (e.g. "1.0.5557.38042"). The Build number is the number of days since Jan. 1, 2000. The Revision number is half the number of seconds since 12:00 AM that day.

If you want, you can use this information to print out a human-readable timestamp (e.g. "3/20/2015 9:08:04 PM"):

 System.Version version = Assembly.GetExecutingAssembly().GetName().Version;
 System.DateTime startDate = new System.DateTime( 2000, 1, 1, 0, 0, 0 );
 System.TimeSpan span = new System.TimeSpan( version.Build, 0, 0, version.Revision * 2 );
 System.DateTime buildDate = startDate.Add( span );
 print( buildDate.ToString() );

This solution was adapted from some other solutions:

  • http://xeophin.net/en/blog/2014/05/09/simple-version-numbering-unity3d

  • http://forum.unity3d.com/threads/automatic-version-increment-script.144917/#post-992135

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 JoeStrout · Nov 09, 2015 at 02:35 PM 0
Share

I've just tested this, and it works perfectly. No custom build steps, no inclusion of Boo, fully cross-platform, and contained entirely within one script. Great solution!

avatar image WillTex · Mar 02, 2021 at 06:25 PM 1
Share

I sadly had to pull this one out because of an issue with asset pipeline v2. It was making the game reimport everything when you changed any line of code. ( https://forum.unity.com/threads/prefabs-are-reimporting-every-time-a-code-change-is-made.939756/#post-6317484 )

avatar image
5

Answer by steinbitglis · Jan 16, 2013 at 04:13 PM

You can use a compile-time language to create a string. At least I know that Boo has this.

 import UnityEngine

 

 macro build_buildtime_info():

     dateString = System.DateTime.Now.ToString()

     yield [|

         class BuildtimeInfo:

             static def DateTimeString() as string:

                 return "${$(dateString)}"

     |]

 

 build_buildtime_info

 

 # # Now you can do this:

 # Debug.Log( BuildtimeInfo.DateTimeString() )






Edit:

Unity actually opens every scene during the build process: This can be exploited as follows:

 using UnityEngine;
 
 [ExecuteInEditMode]
 public class RefreshTestCS: MonoBehaviour
 {
     public string buildName;
 
     public void OnGUI() {
         GUILayout.Label("Build name: " + buildName);
     }
 
 #if UNITY_EDITOR
     public void Awake() {
         if (Application.isEditor && !Application.isPlaying) {
             buildName = System.DateTime.Now.ToString() + " (" + (UnityEditor.BuildPipeline.isBuildingPlayer ? "during build)" : "during edit)");
         }
     }
 #endif
 }


Comment
Add comment · Show 5 · 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 wrxmarcus · Feb 12, 2013 at 09:11 PM 0
Share

Has anyone done the above in C#?

avatar image steinbitglis · Feb 12, 2013 at 09:27 PM 0
Share

I don't think C# can do this, but you can use this class from C# if you place the script under /Assets/Plugins, and the C# code somewhere else.

avatar image wrxmarcus · Feb 12, 2013 at 10:57 PM 0
Share

Thanks. Still being quite new to this, do you know how I would access this info from C#? Does it require an extern - and if so how would I set that up for Boo? I assume I should put this in a file called "BuildtimeInfo.BOO" UPDATE: I find you can call this directly from C#. Too bad Visual Studio is sure this is an error.

avatar image darrinm · May 25, 2013 at 10:17 PM 0
Share

$$anonymous$$y .unity3d web player binary increased by over 500$$anonymous$$ simply by adding this .boo file to my project :( . $$anonymous$$aybe Unity is including a large Boo runtime.

avatar image steinbitglis · May 25, 2013 at 10:37 PM 0
Share

maybe it's debug symbols for boo? As far as I know, there is no "boo" runtime, only ordinary mono.

avatar image
3

Answer by Jaap Kreijkamp · Nov 30, 2009 at 02:26 AM

EDIT: updated code to make copy of string before returning to C#

Okay here it is:

To be able to show date/time of a build (useful to make sure your testers are using the right version) I made a very simple plugin that adds two functions to retrieve date and time string of the build process. To use it, add the Test.h and Test.mm to the xcode project and JBuildInfo.cs to your unity project. Shouldn't be hard to figure out how to use this I guess...

BuildInfo.h:

// BuildInfo.h

import <Foundation/Foundation.h>

@interface BuildInfo : NSObject { }

@end

BuildInfo.mm:

// BuildInfo.mm

import "BuildInfo.h"

@implementation BuildInfo

@end

// Helper method to create C string copy static char* MakeStringCopy (const char* string) { if (string == NULL) return NULL;

 char* res = (char*)malloc(strlen(string) + 1);
 strcpy(res, string);
 return res;

}

extern "C" { const char* getBuildDate() { return MakeStringCopy(DATE); }

 const char* getBuildTime() {
     return MakeStringCopy(__TIME__);
 }   

}

JBuildInfo.cs:

using UnityEngine; using System.Collections; using System.Runtime.InteropServices;

public class JBuildInfo {

 [DllImport("__Internal")] private static extern string getBuildDate();
 [DllImport("__Internal")] private static extern string getBuildTime();

 public static string GetBuildDate() {
     if (Application.isEditor) {
         return "&lt;not build&gt;";
     }
     else {
         return getBuildDate();
     }
 }


 public static string GetBuildTime() {
     if (Application.isEditor) {
         return "--:--:--";
     }
     else {
         return getBuildTime();
     }
 }

}

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 jashan · Nov 30, 2009 at 10:03 AM 1
Share

I think it should be noted that this is a iPhone specific solution.

avatar image CapnCromulent · Dec 04, 2010 at 01:08 AM 0
Share

Has anyone tried to use this recently? In Xcode 3.2.5 / SD$$anonymous$$ 4.2, I receive this runtime error when calling either getBuildDate() or getBuildTime()

malloc: *** error for object 0xce35b0: pointer being freed was not allocated

avatar image Jaap Kreijkamp · Dec 31, 2010 at 07:13 AM 0
Share

You're right, code was wrong, but never gave problems with Unity iPhone 1.7.x, fixed it :-)

avatar image
0

Answer by CapnCromulent · Nov 24, 2010 at 07:14 PM

For iPhone projects, you can use Apple's built-in tool, agvtool, described here. You can probably even use Jaap's answer to provide the generated strings to Unity.

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
  • 1
  • 2
  • ›

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

7 People are following this question.

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

Related Questions

Unity iPhone and SVN 1 Answer

Beast Lightmapping conflict with svn -2 Answers

Properties that version control ignores 0 Answers

Why does Collaborate seem to be checking for changes on a folder it's supposed to be ignoring? 1 Answer

Troubles using Mac + PC with Unity Pro + SVN 3 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