Migrating A Unity 3 Project To Version 4

Posted by on in Development-Blog
  • Font size: Larger Smaller

If you have to migrate a complex Unity 3.x project to version 4 there is more than the SetActive change. See the list of issues I have found and their workarounds. Some of them are specific to iOS, some others are more general in Unity 4 (4.3.4f).

LoadLevelAsync Freezes Screen On iOS

I use Application.LoadLevelAsync to load menus and game levels, the latter most often additively via LoadLevelAdditiveAsync. I observed kind of freezing on iOS in most situations when I loaded a new scene that way. It took about 1-5 minutes to load a very simple scene on an old iPhone 4 with iOS 7.1 compared to < 0.5s on 3.5.7 but could not be reproduced in editor player.

I found out that the problem occurs when Application.backgroundLoadingPriority is set to ThreadPriority.BelowNormal. Setting this to Normal fixes the problem. In version 3.5.7 I never noticed any difference between the distinct priority settings, so the implementation seems to be changed now.

Some postings pointed out to set AsyncOperation.allowSceneActivation to true or false. But I didn't realised any change of the behaviour when setting it explicitly.


Problems With Rigged Blender Model

In RRRunner I used a special strategy to play foot step sounds. The character model has a special bone called MessageBone in parallel to to the regular root bone Hip. MessageBone's X coordinate indicates within all animations which foot has contact to the ground e.g. X = 1 means left foot grounded, X = -1 right foot and X = 0 for both feet at the ground.

A change in MessageBone.X compared to the previous value then triggers playing the appropriate foot step sound. Worked fine in 3.5 but in Unity 4 the message bone was not even existing after the import. I found out that:

  • Bones that have not have set the Deform property are ignored when importing:

  • A rig containing two or more root bones can lead to unpredictable results, so avoid this:
    Eingefügtes Bild


Lightmap Warnings When Using LoadLevelAdditive

In version 4 saw the following warning:

The loaded level has a different lightmaps mode than the current one. Current: Dual Lightmaps. Loaded: Single Lightmaps. Will use: Dual Lightmaps.

The reason was that I always load a LevelBootstrap containing level independent stuff needed in every level. As this level does not contain 3D objects it didn't have a light map. While version 3 did never complain Unity 4 shows the warning. A dummy object in LevelBootstrap and a tiny lightmap made the warning disappear.

Corrupted Info.plist

s. separate posting Unity iOS Build Problem: Corrupted Info.plist

IOException Sharing Violation

I use my own OS project BundleVersionTracker (available on GitHub) to get access to the current bundle version ID from code. It turned out that the following code snippet throws an exception which was fine under Untiy 3:

        using (StreamWriter writer = new StreamWriter (TargetCodeFile, false)) {
        try {
            writer.WriteLine ("{0}", code);
            AssetDatabase.Refresh (ImportAssetOptions.Default);
        } catch (System.Exception ex) {

IOException: Sharing violation on path ... /Assets/Scripts/Config/Generated/TrackedBundleVersion.cs
System.IO.FileStream..ctor ...

To fix this the StreamWriter instance needs to be closed before the call to AssetDatabase.Refresh. In the code snippet above it has to be outside of the using block


GameAnalytics Update

Unity 4 does not support the old GA_Unity3Wrapper.unitypackage provided for Unity 3 users. So I choose to go via Asset Store. I found some problems with the GA_SystemTracker object. Even after recreating it the following error flooded the console:

DrawGUITexture: texture is null
UnityEngine.Graphics:DrawTexture(Rect, Texture)
GA:HierarchyWindowCallback ...

The people at GA quickly answered to my support request and it turned out the logo was not set up correctly. Go to Window / GameAnalytics / Select GA_Settings having the inpector view switched to Debug. There you can set up the property 'Logo' if it is empty:


Warning "Game scripts or other custom code contains OnMouse_ event handlers"

There were some warnings showing up on iOS builds only indicating that there are unnecessary OnMouse* methods:

Game scripts or other custom code contains OnMouse_ event handlers. Presence of such handlers might impact performance on handheld devices.

These are related to MonoBehaviours that contain any methods like OnMouseDown, OnMouseEnter, ... (s. all OnMouse* in MonoBehaviour reference). The problem was that there is no reliable hint where the code is located. So you have to use Find in Files. Most of them was contained in 3rd party vendor code, in my case GameAnalytics and others. It can be fixed temporarily by surronding it with #if UNITY_EDITOR. But after updating to a new version you might need to repeat this step if the code could not be removed by the vendor.


NGUI Update From 2.6.2

I tried out to update to NGUI 3.5.5 and had to rollback everything as my project got totally messed up. So I preferred to just make a minor update to version 2.7.0 (available for downloaded here) although I have the paid version. With Unity 4.3.x there are still a lot of warnings like:

  • Assets/NGUI/Scripts/Editor/ComponentSelector.cs(74,34): warning CS0618: `UnityEditor.EditorGUIUtility.LookLikeControls(float)' is obsolete: `LookLikeControls and LookLikeInspector modes are deprecated. Use EditorGUIUtility.labelWidth and EditorGUIUtility.fieldWidth to control label and field widths.'
    I did a regex search for EditorGUIUtility\.LookLikeControls\(([0-9]*f)\) and replaced it with EditorGUIUtility.labelWidth = $1
  • Assets/NGUI/Scripts/Editor/NGUIEditorTools.cs(704,38): warning CS0618: `UnityEditor.Undo.RegisterUndo(UnityEngine.Object, string)' is obsolete: `Use Undo.RecordObject instead'
  • Assets/NGUI/Scripts/Editor/NGUIMenu.cs(40,30): warning CS0618: `UnityEditor.Undo.RegisterSceneUndo(string)' is obsolete: `Use DestroyObjectImmediate, RegisterCreatedObjectUndo or RegisterUndo instead.'
    In this case I commented out the deprecated code as I do not plan any big changes in this project. If things will change, I will go the major update to NGUI 3.x
  • Assets/NGUI/Scripts/Editor/UIAtlasMaker.cs(122,77): warning CS0618: `UnityEditor.TargetGlesGraphics.OpenGLES_1_x' is obsolete: `OpenGL ES 1.x is deprecated, ES 2.0 will be used instead'
    I commented out the affected code as my iOS project definitely runs on Open GL ES 2.0


CMD + B Still Not Working :-(

I hoped that Build & Run is working with Unity 4 iOS Pro but was disappointed when I saw the old error again:

Launching iOS project via Xcode4 failed. Check editor log for details

I use iOS 6.0 target SDK and the newest Xcode 5.1 (not 4) on Mac OS X 10.8.5. I hate to press more keys than necessary. As a short workaround you use a custom build pipeline (s. Unity iOS Build Problem: Corrupted Info.plist for code sample). To define a hotkey Unity provides a special syntax for the MenuItem attribute. So write [MenuItem("Tools/iOS Build Append %&b")] to get CMD + ALT + B as hotkey to run your custom build pipeline:

So at least the select directory dialog and the append / replace popup don't show up, but you still need to switch to Xcode and hit CMD + R over there. Alternatively you can define the hotkey in system settings but after restarting Unity it's gone and you have to edit system settings again - a no go.

Submit to FacebookSubmit to TwitterSubmit to LinkedIn
Rate this blog entry:


  • No comments made yet. Be the first to submit a comment

Leave your comment

Guest Donnerstag, 29 Juni 2017

Zusätzliche Informationen