Conversion of 1.7 Version to unity3 - Short Story

Hi there, i thought i write a short story on how to convert an older title to unity 3. I have seen some info about that here and there in the forum, so you might have seen some tips already. But putting everything together might be helpful for some of you.

So i was trying to update lucky cats 3d iphone and iPad.

1. Depricated Code

Right after opening the older version in Unity 3 you will most likly see a whole lot of warnings about depricated code. Biggest one is about Touch. So you should change your code accordingly. For example:

var t1 : iPhoneTouch = iPhoneInput.GetTouch(0);

needs to be now:

var t1 : Touch = Input.GetTouch(0);

Note that the Type also changed. Best way to handle this is to use some Texteditor which is able to search and replace text in a directory (BBedit can do that)

2. Strict typing
Unity3 seems to be even more strict than 1.7. You might get some error Messages in XCode, when running on the device - while playing in the editor runs just fine.
I had one issue, where i had strings in an Arraylist which i combined with other Strings in a JS Script. The solution was to change Arraylist to String[ ]. Example:

fieldWords_arr = new string[2];
fieldWords_arr[0] = "field"; 
fieldWords_arr[1] = "fields";

3. .net2 GUIManager and Ani.Mate
Unity 3 “only” offers .net2 and that one doesn´t handle reflection it seems. So this is not really a U3 issue, it was the same in 1.7 when using .net2. In case you used GUI Manager and did some animations, thats also failing on the device.
My solution was to change all the tweens to iTween. That was quite a lot of work. But you can do it, even animation Chaining and Loops. Most often you need to use iTween.valueTo. Example of tweening a QuadObject:

// 1. Nummer einblenden…

void startYourAnimation() {
		Hashtable tweenColorHash = new Hashtable();
		tweenColorHash.Add("from", thisObj.Tint);
		tweenColorHash.Add("to", trans);
		tweenColorHash.Add("time", 1.2f);
		tweenColorHash.Add("easetype","easeOutSine");
		tweenColorHash.Add("onUpdate","tweenColorValue");
		iTween.ValueTo(gameObject, tweenColorHash); 
		
		Hashtable tweenScaleHash = new Hashtable();
		tweenScaleHash.Add("from", thisObj.Scale);
		tweenScaleHash.Add("to", new Vector2(1.5f,1.5f));
		tweenScaleHash.Add("time", 1.2f);
		tweenScaleHash.Add("easetype","spring");
		tweenScaleHash.Add("onUpdate","tweenScaleValue");
		iTween.ValueTo(gameObject, tweenScaleHash); 
		
		Hashtable tweenRotationHash = new Hashtable();
		tweenRotationHash.Add("from", thisObj.Rotation);
		tweenRotationHash.Add("to", new Vector3(0f,0f,720f));
		tweenRotationHash.Add("time", 1.2f);
		tweenRotationHash.Add("easetype","spring");
		tweenRotationHash.Add("onUpdate","tweenRotationValue");
		iTween.ValueTo(gameObject, tweenRotationHash); 
		
		// 2. Nummer auf Icon animieren...
		Hashtable tweenLocationHash = new Hashtable();
		tweenLocationHash.Add("from", thisObj.Location);
		tweenLocationHash.Add("to", new Vector2(xpos,190f));
		tweenLocationHash.Add("time", 0.7f);
		tweenLocationHash.Add("delay", 1.6f);
		tweenLocationHash.Add("easetype","easeInSine");
		tweenLocationHash.Add("onUpdate","tweenLocationValue");
		iTween.ValueTo(gameObject, tweenLocationHash); 
		
		Hashtable tweenScaleToEndHash = new Hashtable();
		tweenScaleToEndHash.Add("from", new Vector2(1.5f,1.5f));
		tweenScaleToEndHash.Add("to", new Vector2(0.5f,0.5f));
		tweenScaleToEndHash.Add("time", 0.7f);
		tweenScaleToEndHash.Add("delay", 1.6f);
		tweenScaleToEndHash.Add("easetype","easeOutSine");
		tweenScaleToEndHash.Add("onUpdate","tweenScaleValue");
		iTween.ValueTo(gameObject, tweenScaleToEndHash); 
}
private void tweenScaleValue (Vector2 value) {
	thisObj.Scale = value;
}
private void tweenColorValue (Color value) {
	thisObj.Tint = value;
}
private void tweenLocationValue (Vector2 value) {
	thisObj.Location = value;
}
private void tweenRotationValue (Vector3 value) {
	thisObj.Rotation = value;
}

4. Texture Import Settings
The importsettings changed a lot, so make sure that every setting is correct and change and reimport if it is not.

5. Self made Shaders
I did not have any issues but some older shaders might not work any more and you need to update those.

6. Physics
I did not have any issues but the physics system changed and you might need to update some settings.

7. OnGui and Stripping
To my surprise a Scrollview did not show up when i used an level of stripping. Seems to be a bug - and there is apparently no workaround. Supersimpleexample (won´t work with stripping)

void OnGUI () {
	GUI.BeginScrollView (scrollPosRect, scrollPos, scrollContentRect); 	
      	GUI.EndScrollView();
}

8 make content for the retina display (iphone4)
Since iPhone4 is now supported you can try to get the best quality out of it by using higher resolution textures.
There is a number of ways on how to do that, its up to you. Usually you need to focus on 2D grafics like gui and Sprites. In my case i used 512x512 textures for older phones and 1024x1024 for iPhone4, swapping textures to the higher version when iPhone4 is detected.

9 Speed on the device
You might run into a speed issue, where your game runs roughly at 50% or slower after you build and run it 1st time on the device. In this case you probably used universal “armv6+armv7 (opengl es1.1 + 2.0)” inside you player settings.
Change that to “Armv6 (openGL Es 1.1)”. If that doesn´t help have a look in xCode at AppController.mm and change the line “#define USE_OPENGLES20_IF_AVAILABLE 1” to “#define USE_OPENGLES20_IF_AVAILABLE 0”.

10 More Speed on iPad
This is no Unity3 tip. Anyways, i always felt that my iPad Version was running sluggish. An FPS test stated ~18FPS.
Meanwhile i knew that using transparent Objects in big sizes is no good idea. So first i got rid of a blob shadow and replaced that with a plane. That resulted in +4 FPS. I reduced the cats meshes: another +4FPS.
But the biggest one was GUI Manager. If you check out the game or have a look at the screenshots, you see a big background picture showing a chinese stone wall with ornaments. This Texture was mapped on a Gui QuadObject, which had the standard GUIManager Shader.
So i dublicated that shader and rewrote it to not use alphas. Shader Script:

Shader "GUIManager/GUIManager Opaque" {
	Properties {
		_Color ("Main Color", Color) = (1.0, 1.0, 1.0)
		_MainTex ("Texture RGB", 2D) = "white" {}
	}
	
	Category {
		//Blend SrcAlpha OneMinusSrcAlpha
		//Alphatest Off
		//ColorMask RGB
		//Cull Back
		Lighting Off
		ZWrite Off
		Fog {Mode Off}
		BindChannels {
			Bind "Color", color
			Bind "Vertex", vertex
			Bind "TexCoord", texcoord
		}
		
		// ---- Single texture cards (does not do color tint)
		SubShader {
			Tags {"Queue" = "Background" }
			Pass {
			
				SetTexture [_MainTex] {
					combine texture * primary, texture * primary
 				}
				
				SetTexture [_MainTex] {
					constantcolor [_Color]
					combine previous * constant, previous * constant
				}
			}
		}
	}
}

That change in another +10FPS. So now it is running on ~38 FPS on iPad.

In case you want tho check it out: i uploaded the iPad version 1.1 yesterday and most likely it will be updated in the store next week.

As for the new Uinty features that apply to iPhone, i cannot say anything about that, as this gae would not benefit from Lightmapping or Occlusion Culling.

Thank you for this report!

I probably must have fallen into the problem n.2 with arrays but also the new physics is quite of a problem here.

Can’t understand why, because the parameters are the usual ones. Something seems changed with the Mass of Rigidbody but also with the SmoothSphereCollision flag…damn…

Investigating more…

Hi, somewhere in the docs OR on the website is information about the physics change. I forgot where. Probably docs. I remember they gave advice how to change your settings to get the former behavior - or at least close.

If anyone has this holy href to share we will appreciate!

Well i had a quick look in the offline Unity Manual and there is a short topic about upgrading projects. Although this link probably will be of no use for you, it might help you to find the page:

file:///Applications/Unity/Unity.app/Contents/Documentation/Documentation/Manual/HowToUpgradeFrom2xTo3x.html

This is the wording about physics:

For Unity 3.0, we upgraded the NVIDIA PhysX library from version 2.6 to 2.8.3, to give you access to many new features. Generally for existing projects, the behavior should be roughly the same as in Unity 2.x, but there may be slight differences in the outcome of physics simulation, so if your content depends on the exact behavior or on chain reactions of physical events, you may have to re-tweak your setup to work as expected in Unity 3.x.

If you are using Configurable Joints, the JointDrive.maximumForce property will now also be taken into consideration when JointDrive.mode is JointDriveMode.Position. If you have set this value to the default value of zero, the joint will not apply any forces. We will automatically change all JointDrive properties imported from old versions if JointDrive.mode is JointDriveMode.Position, but when you set up a joint from code, you may have to manually change this. Also, note that we have changed the default value for JointDrive.maximumForce to infinity.


Well thats not to helpfull i guess

Actually you better do Arm6 + Arm7 and disable ogles2 in appcontroller. There are lot of arm7 specific optimizations

only if you are happy to end with 35mb+ just for the empty project, otherwise this is a horrible idea.

i understand your feeling - but if you come back saying that on newer devices skinning/batching/smth-else work reaaaly slow - you’ve been warned :wink:

Right :wink:
But thats why I added the request to feedback.unity3d.com to get an ARM7 only target with U3 beta5 or so so we can finally stop this ipad OGL ES 2.0 only game unfriendly situation :slight_smile:

I don’t get this Dreamora.
Does arm6/arm7 universal settings compromise the performance on the iPad ?
We are using OGL ES 1 for now, and we are not experiencing problems.

What you mean exactly with: ipad OGL ES 2.0 only game unfriendly situation :slight_smile: ?

I’m guessing he’s referring to the almost double size of the resulting app for smaller apps with these settings. If you don’t care about the 20M cellular download limit then it probably doesn’t matter.