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 dannyskim · Dec 30, 2011 at 01:22 AM · physicsperformanceoptimizationmeshcollidersimulate

Mobile physics optimizations and Mesh Colliders

I've been reading a fairly large amount how to utilize Unity's implementation of PhysX, and I'm getting to the point of frustration on how to get my very simple game to run buttery smooth. Basically, the premise is object's that are spawned randomly from an object pool and you simply dodge them by moving a platform. It's an infinite scroller, nothing very complicated, with some additional physics based powerups.

I'm fairly new to coding, so I've been running with higher application level functions that really shouldn't be utilized, which was one of the first sources of optimization for my code.

I was previously using LINQ for my object recycler, but I've digressed to using simple random number queries to search through my List(T) instead of reducing the size of my code by using LINQ. So far, from the profiler, it seems physics.Simulate is causing slight frame rate stutters occasionally, nothing to make the game come to a screeching halt or even effect gameplay significantly, but it bothers me that such a lightweight game is taking a nasty hit from Physics.

My game is using MESH COLLIDERS, and I read somewhere in the documentation that utilizing gameObject.SetActiveRecursively() or gameObject.active causes re-computation of the mesh vertex collision information every time it's activated. So this is fairly large cause for concern, since objects are being spawned progressively faster and faster and I'm utilizing these calls every 0.33 seconds at the hardest difficulty. Once again the game doesn't come to a screeching halt, but stutters are noticeable to an observant eye. As a note, I've tried using compound primitive colliders and this didn't have any appreciable effect on performance, if anything performance was almost exactly the same. The most complicated Mesh Collider has only 28 faces ( using mesh colliders for more accurate collisions since object's have fairly random shapes ). I realize that performance optimization has it's cap with much higher poly numbers so having 28 faces doesn't matter compared to something that has a much higher count.

Does anyone have extensive physics experience with Unity3D and Android / iOS to recommend some performance tips to further optimize this scenario? I have taken a deep look into profiling my game over the past week and when the Physics.Simulate spikes, my frame rate on my MBPro drops from 1500+ fps to 500 fps, and I'm having a hard time pinpointing the direct transgressors. I am making extensive use of OnCollisionStay / Enter / Exit calls, but when profiling these don't seem to be the source of computation time under this group hierarchy, just generally under Physics.Simulate. Some direction or recommendations woud be greatly appreciated.

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Antony-Blackett · Jan 07, 2013 at 02:06 AM

Firstly make 100% sure that it is the physics that is slow. The profiler can sometimes be misleading. Use the iOS Unity internal profiler on your device and see if it says the physics is taking all the time, you may find that on the device it might be waiting on the GPU or something else.

If it is the physics then try: Do all your objects have Rigidbody components? If not try adding them as the physics system will assume these objects are going to change over time. If they don't it'll assume they are static objects and pre-calculate a buch of stuff to make them run 'faster' this pre-calculation itself is slow though and is intended to only be done at the start of the level once.

Another thing to try is activating and deactivating objects using layers instead of gameObject.active = false/true. To do this create a layer called Deactivate. Make sure no cameras render that layer and also in the Physics settings make sure no other physics layers collide with that layer. Then set that object and all its children to that layer instead of using gameObject.active. This will not remove and add the objects from the simulation every time they change layer instead the camera and physics simulation will just ignore them. The downside is that they will take up more overhead and other scripts on those objects will still be running when they are in the disabled layer unless you disable all of them manually as well, so if you have a lot of objects doing this then it my be slow because of all the overhead.

Hope this helps.

Comment
Add comment · 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

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

6 People are following this question.

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

Related Questions

Character Controller's performance for massive groups 0 Answers

Improve Physics Performance For large Number of Objects 1 Answer

Understanding Raycast How Actually works in Unity [As Algorithm] 2 Answers

Add 2d rigidbodies to moving objects to increase performance or not? 1 Answer

Physics calculates collisions between disabled layers 0 Answers


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