Archive for April, 2013

Unity: my object’s physics doesn’t work ? why ?


I stumbled onto this issue and solved it.

So, I had a 3D object with a collider on it and it was not acting as a collider.

I had a script on that object which animates its movement through transform.lerp in a update funtion

Why was the physics not working ?

It is because if you update the object’s position on each frame though functions like transform.lerp, it bypasses the unity’s physics calculations on that object (even the child objects attached to it) and hence no physics works on it. So, I ended up using a character controller on it.

How to split apk and generate obb for google play store using Unity 3.x and Windows. (Also works on Mac, haven’t tested it)

Hi guys,

I saw a lot of posts and I could not find this tutorial anywhere. So, I am posting it here for others. Scroll to the end to find my scripts.

I actually started with this great tutorial written for unity 4

Here are the steps for unity 3.x

0) Add the GoogleOBBDownloader package from AssetStore. Now go to GooglePlayDownloader.cs and change the PUBLIC_KEY in it to match yours

1) Create a new scene called “Scene 0”. Add a empty game object and attach the script “DownloadObbExample.cs”

2) go to build settings and select only “Scene 0” and build the apk file from it.

Note: Make sure you fill out public key, keystore, version and package name in player settings.

3) Now add the script BuildStreamedSceneAssetBundle.cs in Assets/Editor

4) Edit the script to add all the levels you want to package

5) You wil see the option BuildWebplayerStreamedLevels in Build menu of unity. Use that to build asset package which is a .unity3D file

Note: asset packages are not distributable. Hence, you have to edit this line in the BuildStreamedSceneAssetBundle.cs for each platform and rebuild the asset package

BuildPipeline.BuildStreamedSceneAssetBundle(levels, “Levels-AssetBundle.unity3d”, BuildTarget.Android);
//for pc and mac use BuildTarget.WebPlayer and for Iphone use BuildTarget.Iphone

6) Rename your asset bundle as ” main.versionNumber.packageName.obb” (versionNumber and packageName should match the ones in step 2)

Note: if you have multiple .unity3D files you can zip them together and then rename that zip file as above

7) Upload them both on google play and your game should load smoothly.

Here is my code from “DownloadObbExample.cs”
public class DownloadObbExample : MonoBehaviour
private string expPath;
private string logtxt;
private bool alreadyLogged = false;
private string nextScene= “StartingLevel”;
private bool downloadStarted;
private string progress=” “;
void log( string t )
logtxt += t + “\n”;
void OnGUI()
GUI.Label(new Rect(10, 10, Screen.width-10, Screen.height-10),
logtxt+” “+progress);
if (!GooglePlayDownloader.RunningOnAndroid())
GUI.Label(new Rect(10, 10, Screen.width-10, 20), “Use GooglePlayDownloader only on Android device!”);
expPath = GooglePlayDownloader.GetExpansionFilePath();
if (expPath == null)
log (“External storage is not available! “);
string mainPath = GooglePlayDownloader.GetMainOBBPath(expPath);
string patchPath = GooglePlayDownloader.GetPatchOBBPath(expPath);
if( alreadyLogged == false )
alreadyLogged = true;
log( “expPath = ” + expPath );
log( “Main = ” + mainPath );
if (mainPath != null)
if (mainPath == null)
GUI.Label(new Rect(Screen.width-600,
Screen.height-230, 430, 60),
“The game needs to download 200MB of game content. It’s recommanded to use WIFI connexion.”);
if (GUI.Button(new Rect(Screen.width-500, Screen.height-170, 250, 60), “Start Download !”))
protected IEnumerator loadLevel()
string mainPath;
yield return new WaitForSeconds(0.5f);
mainPath = GooglePlayDownloader.GetMainOBBPath(expPath);
log(“waiting mainPath “+mainPath);
}while( mainPath == null);
if( downloadStarted == false )
downloadStarted = true;
string uri = “file://” + mainPath;
log(“downloading ” + uri);
WWW www = WWW.LoadFromCacheOrDownload(uri , 0);
while( !www.isDone )
progress = Time.time+” “+ http://www.progress;
yield return null;
AssetBundle ab=www.assetBundle;
if (www.error != null)
log (“wwww error ” + http://www.error);
log(” ab is null “);
log(Time.time+” loaded ab”);
here is my code for BuildStreamedSceneAssetBundle.cs
using UnityEngine;
using UnityEditor;
using System.Collections;
public class BuildStreamedSceneAssetBundle : MonoBehaviour {
public static void MyBuild(){
string[] levels  = {“Assets/Scenes/level01.unity”,
BuildPipeline.BuildStreamedSceneAssetBundle( levels,
“Levels-AssetBundle.unity3d”, BuildTarget.Android);
%d bloggers like this: