Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by jim_bbq · May 23, 2014 at 12:25 PM · iosiphoneperformance optimizationperformance metrics

iOS performance problem (iphone 4 on iOS6)

Dear all

I have a problem with the iOS performance of a simple 2D game.

Normally, it runs very smoothly showing stat A. Occasionally, I notice during collision detection, there is a noticeable delay .

I have tried to move a lot of the codes away from Update(), and put the codes in coroutine. this did improve the performance slightly but still the delay persists. Then I changed all my colliders from 3D to 2D. Also I replaced the default onTriggerEnter/Exit/Stay with custom-made functions using raycasting to detect trigger events.

Still I have a delay problem every now and then (see stat B)

Any clue how I could address this problem? thanks a lot for your help!

A

 ----------------------------------------
 iPhone Unity internal profiler stats:
 cpu-player>    min:  3.8   max: 12.0   avg:  7.2
 cpu-ogles-drv> min:  0.5   max:  2.6   avg:  0.9
 cpu-present>   min:  0.8   max: 162.9   avg:  6.8
 cpu-waits-gpu> min:  0.8   max: 162.9   avg:  6.8
  msaa-resolve> min:  0.0   max:  0.0   avg:  0.0
 frametime>     min: 12.2   max: 193.5   avg: 37.1
 draw-call #>   min:   7    max:   7    avg:   7     | batched:     2
 tris #>        min:   314  max:   314  avg:   314   | batched:     4
 verts #>       min:   628  max:   628  avg:   628   | batched:     8
 player-detail> physx:  0.7 animation:  0.3 culling  0.0 skinning:  0.0 batching:  0.2 render:  3.5 fixed-update-count: 1 .. 9
 mono-scripts>  update:  2.4   fixedUpdate:  0.0 coroutines:  0.2 
 mono-memory>   used heap: 585728 allocated heap: 786432  max number of collections: 0 collection total duration:  0.0
 


B

 ----------------------------------------
 iPhone Unity internal profiler stats:
 cpu-player>    min:  3.0   max: 436.8   avg: 20.9
 cpu-ogles-drv> min:  0.5   max:  3.5   avg:  1.1
 cpu-present>   min:  0.8   max:  6.0   avg:  1.9
 frametime>     min: 22.4   max: 470.1   avg: 46.9
 draw-call #>   min:   8    max:  10    avg:   8     | batched:     2
 tris #>        min:   218  max:   228  avg:   224   | batched:     4
 verts #>       min:   436  max:   448  avg:   442   | batched:     8
 player-detail> physx:  0.9 animation:  0.1 culling  0.0 skinning:  0.0 batching:  0.1 render:  3.2 fixed-update-count: 1 .. 17
 mono-scripts>  update:  1.6   fixedUpdate:  0.2 coroutines: 14.5 
 mono-memory>   used heap: 618496 allocated heap: 786432  max number of collections: 0 collection total duration:  0.0
Comment
Add comment · Show 4
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image MakeCodeNow · May 23, 2014 at 04:55 PM 0
Share

How much garbage are you generating? Periodic hitching could be collision if it happens when a lot of objects collide, but if it's just kind of "random" then garbage collection could be the problem.

avatar image Fattie · May 24, 2014 at 07:47 AM 0
Share

it's very hard without the profiler. Just FTR, commercially, I just don't know if iOS6 matters much anymore. 90%+ of income comes from people with normal phones, not ancient ones.

avatar image jim_bbq · May 27, 2014 at 10:56 AM 0
Share

Dear all

thanks for your kind reply! it is very helpful. I have been doing some research online and going through my codes. I did use a lot of instantiate() and destroy(). For instance, when an enemy is destroyed, some coins are "instantiated" for collection (and destroyed once collected)

Unfortunately I don't have Unity Pro, but I am guessing I need to study a bit on Object Pooling to avoid frequent instantiation and object destruction. I hope this will solve my problem!

avatar image meat5000 ♦ · May 28, 2014 at 09:56 AM 0
Share

RayCasting will have slower performance than Collision/Trigger functions aside from Stay.

OnCollisionStay and OnTriggerStay will really chew up the CPU as it bangs out every frame ins$$anonymous$$d of just once. If you have just 1 CollisionStay it can really damage performance. Having many == Death to App.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Tarlius · May 23, 2014 at 05:23 PM

"Delay problems" usually points at the Garbage Collector. If you are using Unity Pro (I forgot if you need pro for that info) you can use the Profiler to look at the GC allocations which will eventually add up to the point the GC kicks in and kicks your performance in the balls for a frame.

If Unity Free.... Ummm... You're stuck checking the code yourself :/

Basically, try not to allocate "new" objects every frame. Pretty much any time you use the "new" keyword with a class (as opposed to a struct), you're asking for GC-managed memory and when it runs out it checks which objects don't have references and frees the memory for reuse which is rather slow.

Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image jim_bbq · May 28, 2014 at 09:45 AM 0
Share

I am a bit stuck now! I have implemented an object pool function that instantiates all needed objects in the game and activate and deactivate them during the game, thus removing the need of instantiate() and destory(). the problem still won't go away!!! I don't think it is the collision either as I only use collision to detect if the player touches the object....

what else could have caused this problem??

avatar image jim_bbq · May 28, 2014 at 10:58 AM 0
Share

as it turns out, the main culprit in this problem is NGUI which I use for GUI. I display two text labels for scores and lives with NGUI and once I removed them, everything seems to be running smoothly! curses!

avatar image Tarlius · May 30, 2014 at 02:39 PM 0
Share

NGUI is generally pretty lightweight... I guess its possible you hit an edge case or something, but I think its more likely theres a different underlaying issue :/

Without access to the profiler its hard to help much, but gc still sounds likely.

What are you actually doing in the collision logic? How many objects do you have?

avatar image Fattie · Jun 02, 2014 at 04:39 AM 0
Share

Hey @jim - here's my "famous" cough explanation of pools for new programmers (not us guys!) who were asking about it.

http://answers.unity3d.com/questions/321762/how-to-assign-variable-to-a-prefabs-child.html

Conceivably, you have some woe in your pool handling (maybe, looking up a game object too often or something). You may enjoy reading it. Please vote it up as I need moar points :)

avatar image Fattie · Jun 02, 2014 at 04:43 AM 0
Share

i worry about using ngui. and i jus don't like unity's gui. (although it has no performance problems) do you have "a lot of gui"? we always just use 2dtoolkit and do the gui as totally normal, ordinary, stuff in the 3d scene, the "normal" way to do buttons etc. 2dtoolkit has button functions etc builtin and ready to go.

Performance is difficult, Jim. We recently did quite a big project for a client, with unity i mean, that had a lot of flat images. in fact - in the end it just wasn't possible to use unity. we re-did the whole project as a normal native project.

On the other hand very often there's just "some stupid thing" that 's causing the woe.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

24 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Unity iOS sdk question 1 Answer

iOS Shader - Emulator vs Device Inconsistency 0 Answers

WebCamTexture and VSync (iPhone 4) 3 Answers

Depth of Field Mobile 0 Answers

Making the switch to iPhone 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges