Things not to do in Unity Android

Today marks my 6th day deving with Unity Android Pro, and I’m not going to lie… it’s been a very frustrating week.  I’ve got enough material to fuel four or five posts, but I’ll try to keep this one brief and hopefully help some people out.

Firstly, let me remind everyone that I was a Flash dev for the better part of a decade, and unfortunately this has permanently damaged my programming mindset. In Flash you find yourself moving objects around the stage in incremental steps… something along the lines of:

player.x += 1;

In flash this is fine.. and if you’re going to move things in Unity this kind of method works too… But that’s Unity for PC or Web… Now we’re working with Unity Android…

If you take anything away from this post, please take this. Android only cares about one thing. CPU Cycles. If you have an update loop and you’re moving something with += 1, you’re going to hate yourself.  Things will run very choppy, laggy, and freezy (depending on your phone). The most frustrating thing is when you’re testing this on your PC or Mac, it’ll work just fine! That’s because your PC and Mac process things completely differently than Android.

The tools you’ll use in Unity to save you from all this is Lerp, Slerp, and Translate. Also Mathf.Clamp, Floor, and Ceil are super important because Android will not calculate math quickly enough to keep up with your loop.  For example, say you want to rotate an object 90 degrees… well you better write that 90 degrees like Mathf.Ceil(90) otherwise your object will miss the 90 mark completely and keep spinning.

So remember kids, Lerp, Slerp, Translate and use your Mathf or you’ll be sorry…

Advertisements

1 Response to “Things not to do in Unity Android”


  1. 1 Sriram October 19, 2011 at 1:05 pm

    Thanks a lot for this post. Solved many issues i had. One main query. How easy is it to integrate Facebook likes/ twitter post stuff into the android app? Could you point me on to some leads.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s





%d bloggers like this: