• 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
2
Question by andyisbonza · Aug 11, 2013 at 05:24 AM · collisionphysicsrigidbodyperformancekinematic

Are my kinematic rigidbodies slowing my scene down?

My scene consists of a bunch of kinematic rigidbodies which I manually move around - I am not using gravity or forces at all. I have a road object, car objects, etc - all are kinematic rigidbodies. You can also shoot bullets (also kinematic rigidbodies). The bullets are the ones with the onTriggerEnter handler - the code checks the tag of the other object and figures out the appropriate behaviour of both the bullet and what it has hit. There aren't any other collision event handlers.

I am worried that because I've placed my objects on top of each other (i.e. the car wheels are touching the road, the buildings sit on top of the road), they are generating collisions every frame and slowing everything down. The performance of my game is not great given the relatively small amount of stuff I have going on and I'm wondering if this is the cause of it. The gameObjects are constantly moving, so I have the feeling they're not falling asleep. Would this be the case? If neither of two kinematic rigidbodies have onEventTrigger handlers, does it still cause a hit on the CPU? I.e. the buildings and road are both moving at the same rate and touching each other the whole time - even though neither have onTriggerEvent handlers, would this cause slowdown?

If this is the case, is it as simple as repositioning the objects so they're not touching each other (but are very close) and then set their rigidbody sleepVelocity value to the speed that they are moving at (as they all move at a constant pre-defined speed). Is this reasonable? Or am I totally off and I need to go back to the drawing board?

Many thanks for any assistance/insight that can be provided!

Comment
Add comment · Show 6
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 Benproductions1 · Aug 11, 2013 at 09:17 AM 0
Share

Why do you need so many rigidbodys? Think of it this way: The more objects you have idling, the slower it will be. If you're not doing any collision checking, then why have kinematic rigidbodys at all? (Yes, most of the time there is no difference in performance between very close, non colliding objects and colliding objects)

avatar image andyisbonza · Aug 11, 2013 at 02:12 PM 0
Share

Thank you for the reply. The reason I have so many rigidbodys is because each can potentially be hit with a bullet, so the bullet needs to have something to collide with and react to.

The buildings/cars scroll past from right to left. At any one time, there are a maximum of maybe 20 in the game. I create them offscreen on the right, move them through the scene to the left, then destroy them when they're offscreen. I might try sleeping them as they are created, and setting a sleepVelocity as their current speed (which remains constant throughout their life). If they're hit by another kinematic rigidbody (i.e. a bullet or the player), that should wake them, correct? Would this help with game performance?

The other thing I have considered doing is not creating/destroying the gameObjects as they're needed - ins$$anonymous$$d I would create everything at the start of the game and leave each object sitting idle until needed, resetting them once they've been used and effectively recycling them. Potentially helpful?

Thanks!

avatar image whydoidoit · Aug 11, 2013 at 03:06 PM 0
Share

Well definitely avoid instantiating things when the game is playing - that's a killer on performance.

Perhaps its the performance of your collision handling code, could you post some?

avatar image Benproductions1 · Aug 11, 2013 at 10:46 PM 0
Share

You do know, that you do not need a rigidbody on both sides of the collision? From what I understand you just have a bunch of moving geometry and a bullet. Unless you want that geometry to affect physics (move things), there is no need for rigidbodys to be attached to it.
Always avoid Instantiating, but you should also use the profiler (in pro) or just the stats popup (in free) to see what is causing your performance drop.

avatar image andyisbonza · Aug 12, 2013 at 10:47 AM 0
Share

Benproductions: You're right... I didn't realise that I didn't need a rigidbody on both sides of a collision. I got that notion from the Unity doco, which seems to say that if you're planning on moving an object, it needs both a collider and a rigidbody:

A Static Collider is a GameObject that has a Collider but not a Rigidbody. Static Colliders are used for level geometry which always stays at the same place and never moves around. snip

Static Colliders (without a rigidbody) should not be disabled, enabled or transformed. Altering these Static Colliders will cause an internal recomputation in PhysX that is quite expensive and which will result in a big drop in performance.

But after reading and re-reading, I think they're talking about objects under the control of the physics engine, and not objects that you can move around. I guess I got confused because they talk about static colliders right after kinematic rigid bodies (http://docs.unity3d.com/Documentation/Components/comp-DynamicsGroup.html)

So I will try removing the rigidbodies from everything except my bullets and see how that improves things. I will also alter the code to recycle the gameObjects rather than create/destroy.

Show more comments

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by briosh · Jan 05, 2014 at 10:32 AM

Very helpful thread - I'd like to add my experience too.

In short: DON'T use rigidbodies on both sides and dont use them even as kinetic in objects that will not behave 'physically' i.e. debris or falling rocks. Keep using them though in projectiles and remember to move them with velocity or forces NOT directly through transform.

The details: Following the unity docs i added one kinetic rigidboy to the root transform of my collidable objects. I use path finding to move around 40-50 enemies at the same time. Since path finding already keeps nav agents from getting inside one to another, the rigidbodies where usefull only for my custom collision checking.

BUT, It turns out that since the bullets are already rigidbodies and the player is a character controller, ALL collision AND trigger events fire correctly WITHOUT the rigidboies and performance also went up from 23fps to 57-70fps even IN the editor!

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
avatar image
0

Answer by ocdy1001 · Jul 18, 2014 at 11:42 AM

well, the amount of rigidbody's could be a problem with mobile devices, but keep in mind that a moving rigidbody is ALWAYS faster then a object that is moving without rigidbody. The engine doesnt expect a not rigidbody-object to move. even if you don't need physics, a object wich is gonna to move should have a rigidbody! if you dont need physics, set it to kinematic. it is faster. this is said by people working at unity.

hope this helps

Comment
Add comment · Show 2 · 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 Jaqal · Jul 20, 2014 at 02:01 AM 0
Share

$$anonymous$$y problem with this is I have a tons of trees in my game most which can be cut down. I have rigidbody's on the ones that can be cut but its killing my performance right now.

avatar image ohokke · Feb 25, 2015 at 11:06 AM 0
Share

Add them dynamically when a tree is about to be cut?

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

18 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

Related Questions

Rigidbody and Parenting - Kinematic Rigidbodies? 2 Answers

Preventing objects from intersecting with minimal physics 3 Answers

Simple Movement Game: Physics vs Manual Collision Detection? 2 Answers

Disable rigidbody from being able to move other rigidbodies 1 Answer

[SOLVED] Desactivate pushing forces between two objects 2 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