• 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 hav_ngs_ru · Jan 28, 2015 at 05:27 PM · performancecomponents

How significant could be overhead if I split one "all-in-one" component into about 3..5 focused

I'm making some refactoring of my project to reach more scalability and possibly to improve performance (the second is not the goal, it would be enough if I just not worsen it).

Generally, I'm splitting one "all-in-one" unit controller script to several focused ones. And a question is - how significant could be overhead caused by additional component's Update/FixedUpdate calls and other extra work engine will do to handle a presense of 5-10 new scripts attached. I'm speaking about mobile platform, 20-30 active units in scene and 5-10 additional scripts after full refactoring.

There are some details. I had one unit contoller with one FixedUpdate where several tasks was performed:

 void FixedUpdate() {
   //applying control commands from my control manager
 
   //calculating and applying additional forces 
 
   //scanning space around and appliyng additional behaviour 
   //(no-the-way inteacting with some objects near unit, with shpereoverlap and raycasts)
   
   //calculatimng and apliyng visual effects 
   //(engine lights, dust emission, sounds...)

   // and so on
 }


now I want to have different components, each of them for its own job.

 public class MoveComponent {
   void FixedUpdate() {
     //applying control commands from my control manager
 
     //calculating and applying additional forces 
   }
 }
 
 public class InteractingComponent {
   void Update() {
     //scanning space around and appliyng additional behaviour 
     //(no-the-way inteacting with some objects near unit, with shpereoverlap and raycasts)
   }
 }
 
 public class EffectrsComponent {
   void Update() {
     //calculatimng and apliyng visual effects 
     //(engine lights, dust emission) and sound effects (engine sound based on it's force) and so on
   }
 }



So, I would get a comfort way to use new behaviours, effects and assemble new Units by combinating different parts. I even expect some performance growth because some calculations moved from FixedUpdate to Update (called almost twice less).

But I'm worrying about overhead that can be caused by adding 10 components to GO instead of 1 component. I'm talking about 20-30 active units in scene, on mobile platform. I'm below 20fps now already. Yes, there some things to optimize, but i'm walking on a edge already, and it makes me doubt about everything :)))

I havent made any benchmarks because I only started a refactoring yet... but does it worth the trouble? Couldnt additionals components hit the performance significally?

Thanks in advance to everyone for any thoughts, any facts from your experience and for any advice :))

Comment
Add comment · Show 1
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 hav_ngs_ru · Feb 02, 2015 at 10:36 PM 0
Share

I'm still in the middle of the way , so Im still not able to do some benchmark . $$anonymous$$oreover - I got carried away , now I expect not 5 , but rather the 10-15 components in each GameObject .So I still have a question... and still will be grateful for any information :)

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Baste · Feb 02, 2015 at 11:05 PM

So there will be some overhead in adding extra components, but it will probably be very, very small. In fact, I doubt it will be a measurable difference. There will be 10-15 Update calls instead of 1, but just the method call is just some very few machine instructions.

If you want to optimize, there's some very easy ways I can think of that should have a big effect:

  • Make sure that you're not doing any GetComponent, FindObjectByName/Tag/Type calls in your Update or FixedUpdate methods if you could instead do that in Start, and store the result for later use

  • If you're using physics, go into your collision matrix, and turn off collision between all layers that are not colliding. If you have objects in the scene that will never collide, but are on layers that have objects that will collide, consider adding extra layers. The less calculation, the better

  • If you're moving an object with a collider, always make sure that it has a rigidbody on it. Unity assumes that colliders without rigidbodies will never move, and is optimized for that.

  • If you're in 3D, replace any mesh collider you can with box and sphere colliders.

Comment
Add comment · Show 1 · 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 hav_ngs_ru · Feb 02, 2015 at 11:20 PM 0
Share

thanks for your answer.

I know all thees steps for optimizing but "moving collider without rigidbody"... Are you sure for this?

I have moved all my bullets (and there could be hundreds of them at same time during the battle) from rigidbody-collision to sphereoverlap collision detection, because of idea "less rigidbody - less collision calculations"... and now it onfused me... If my (sphere) collider moving in both cases - is it really worse to have rigidbody with OnCollisionEnter that to have no rigidbody but to SphereOverlap every FixedUpdate?

And what about components: I guess, the main question will be "does Unity cache Update/FixedUpdate methods"? I know that Unity uses Reflection to detect is there Update (ad other) methods in each component and to find it's adress, and searching thees methods definetely causes overhead... But does Unity every time searched thees methods, or it caches it after they found once?

If it does - so there are really almost no difference between 1 Update or 10 Updates. But if it does not - it will be trouble -))

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

20 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

Related Questions

Does a large number of components will affect performance ? 2 Answers

C# - AddComponent Vs GetComponent 1 Answer

System or Unity Action? 1 Answer

Speed and efficiency of enabling/disabling component? 1 Answer

Performance questions (mobile), object pooling 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