Unity – auto set Android password in project

Hey, it’s time for an other tip today!

There are small details in Unity which can make you crazy: compiling an Android project with the correct certificate request you to provide the password each time you open the project. Ok, that’s not a big deal! But the problem is: if you miss to write it and launch the compilation it will be at the end of the process than you will be informed you didn’t set it up and so it fails. With a 30 minute build time (on a big project), if you miss it, you’ve the right to be angry! Why the hell Unity doesn’t check it before!?

Anyway let’s make a small Editor Script:

using UnityEngine;
using UnityEditor;

[InitializeOnLoad]
public class StartUp {

	#if UNITY_EDITOR

	static StartUp() {

		PlayerSettings.keystorePass = "myPwd";
		PlayerSettings.keyaliasPass = "myAliasPwd";
	}

	#endif
}

Thanks to this script, when the project will be opened the password will be registered!

Ok an other thing to figure, the keystore path is saved in your ProjectSettings.asset. So the path need to be changed on each computer. Not a big deal, but it could be done automatically if it’s near your project. On the script above, add:

PlayerSettings.Android.keystoreName = Application.dataPath + "/user.keystore";

The last thing to do would be to reset this path when Unity goes in the background so you can git push/pull without creating conflict. Unfortunately I can’t find a way to detect correctly when Unity goes in background, see http://forum.unity3d.com/threads/trapping-if-unity-editor-is-foreground.271391/. Do you know a way to do it?

Unity – fast build platform switcher script!

Today a quick tip for a huge trick!

Working with Unity is pretty awesome until you have to make a build on an other platform than your current one! Depending your project size (number of assets etc.), just changing your current platform for Android to iOS or vice versa could take one hour… yup seriously! During that time you won’t be able to work on your project and your computer’s CPU will be pretty busy… so time for a long break? Until now!
Continue reading Unity – fast build platform switcher script!