Unity iPhone game development tricks

Source: Internet
Author: User
December 13,200 8

I started programming on Unity last 2 months. in the mean time I tried to collect what to do and what not based on my experiment and Forum's people experience. here is a list that might help when you will develop a iPhone game in unity.

Optimizing factors:

Technique:

· Combining textures into atlases and combining meshes is always a good idea. for each separate mesh or mesh subset you pay not only the cost of opengles render-call, but also unity has to do work processing shader/material settings. this is a global way of rendering.

· Use as less different textures (combining them into Atlas is the way,
· However you shoshould be careful about pvrtc compression artifacts ).

· Use less different materials (same shader with different parameters is counted as different material) as possible.

· Even if you can't combine meshes, it will not increase performance for you today, but will open door for future optimizations.

· If you have lots of very small dynamic objects, you can try combining them into Skinned Mesh and animating bones.

· Be aware in time scale and time fixed setting in your project

· Reasonable with 2-3 characters simultaneously on screen

· The stats button in the game window in unity is your friend. watch there the draw CILS. I found those as most limiting parameter for iPhone rendering.

· Even GUI stuff uses draw CILS. Check if you can combine rendering of GUI elements to save draw CILS.

· Use the diffuse fast shader, not diffuse or vertex. speeds up a lot! As test, enable the stats window, look at the draw CILS. now have your test model once use the diffuse shader and once the diffuse fast shader and watch the difference in draw CILS.

· The Rigidbody shocould be fixed in the rotation axis. this is a checkbox you can activate in a Rigidbody. of course does not work for every kind of model, but for less important object we can use it.

· Removed the background (sky box) and used a solid color for clearing the background. Please CES the draw callfrom 6 to 1 if you used before a skybox.

· Try to increase the physics timing as much as possible. It's depending on the project. greatly affects frame rate.

· Also watch the texture import settings of every texture. Check if you can live with 2 bits compression and only RGB instead of rgba.

· Force audio files to be mono. Might save lots of memory.

· Having lots of audio sources in the game costs performance, at least my experience.

· Carefully think of your menus if they use lots of images. if they are in the same scene as your game, those images eat a lot of the very tiny ram of the iPhone. might make sense to put the menu into a separate scene file, otherwise it cocould happen people complain your game quits unexpectly on their phones (often because of too less free memory available ).

· Try putting on group go's the "mesh combine children" script. had great success with that!

· Do not use Alpha testing on iPhone if you can. Alpha test is way much more expensive than alpha blending on iPhone (contrary to PC/MAC ).

· If you go about 25-30 draw CILS per frame, you will cross the 30fps threshold and it will drop to about 15fps immediately.

· Each material on each mesh causes one draw-call per frame, per light that affects it and per camera that sees it.

· If I have 1 mesh with 20 seperate textures, only ambient light, one camera, this will also result in 20 draw-CILS. if I wocould combine the 20 textures into one Atlas the scene wocould now only need a single draw-call.

· If I have 20 meshes with one texture each, only ambient light, one camera, this will result in 20 draw-CILS. if I wowould combine all the textures into one big Atlas, the scene wowould still require 20 draw-CILS, even though all the objects wowould now use the same texture.

· The Only Way to optimize here wocould be to combine meshes. But you can only do that if your meshes aren't to move around und independently from each other.

· Mesh_draw_cils = visible_meshes * mesh_subsets * number_of_passes_per_material;

· If you have skybox (+ 6), Gui, participant, trails, projectors etc.

· Using compressed textures is very important in order to save on memory bandwidth, not that much of just saving memory.

· Pvrtc compression allows to use 8 or 16 times less bandwidth and provides better GPU texture cache utilization. note that memory between CPU and GPU are shared on iPhone making bandwidth ever more important. for example rendering full-screen quad with 2 512 × 512 textures takes ~ 20 ms without compression and ~ 12 ms, if textures are pvrtc4bpp compressed. Roughly twice as fast.

· Pvrtc it is for the game, uncompressed for the GUI, 20 mb total texture, 60 MB for the game, build compressed 1024 Atlas 'to blanket the level with breakpoints that balance texture quality with draw CILS.

· You can define onapplicationquit () function to handle application termination. However it will work only since 1.0.1 (hotfix) release. Same for playerprefs.

· GUI. buttons and GUI. xxx stuff is much heavier than guitexture. parts of GUI. xxx are written in C # and rendering is much more complicated due to custom skins. just use guitexture in game.

· There is a bug in openal implementation on iPhone audio. So, don't panic about more than 2 sounds at a time. iPhone unity 1.0.1 will include workaround for it.

Scripting:

· If you use JS, typing your variables is a must. had some variables untyped which unity did not complain about and those in an update cycle were heavy FPS cost. so watch our _ every _ variable you use if it is typed or not.

· Use # pragma strict in every JS script in the first line.

· Put in every script that uses GUI stuff in the awake () function this line: useguilayout = false;

· Try to avoid lookups like gameobject. find ("some go"); if you can't avoid, do them one time in the START () function, but not in update/fixedupdate. try to put in your script a variable to your objects you want to reference and assign them via the unity editor. the best reference is the one statically linked!

· Don't do anywhere string comparisons inside update or fixedupdates. ultra expensive. Use integers for comparisons.

· Don't use tags on gameobjects to compare something, same as abve. Expensive!

· Try to find out if stuff in your update/fixedupdate _ Really _ needs to be calculated every frame. Use integer counters in update and do some calculations only every nth frame.

You may find reference of this list on following URL.

Http://forum.unity3d.com/viewtopic.php? T = 16214

Http://forum.unity3d.com/viewtopic.php? T = 16079

Http://forum.unity3d.com/viewtopic.php? T = 15597

Https://developer.apple.com/iphone/library/technotes/tn2008/tn2230.html

Http://www.imgtec.com/factsheets/SDK/PowerVR%20Technology%20Overview.1.0.2e.External.pdf

//////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// //

Http://shohagsust.wordpress.com/2008/12/13/unity-iphone-game-development-tricks/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.