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 feneq · Oct 06, 2013 at 08:36 AM · physicsrigidbodyperformanceoptimizestacking

Is there anyway to optimize my physics based game?

Sorry, my question is fairly vague. My game is about stacking objects. The problem is, while stacking high is not the only way to obtain points, it is still one viable way to get a high score in my game. This leads to many rigidbodies stacked on each other. I noticed on my phone that after stacking quite a few objects, the performance went down a bit. Not too much but still it was a noticeable drop. I assume performance will continue to go down as more objects are stacked. Did I just poorly design my game or is there something I could do when handling many rigidbodies? I'm trying to think of ways to keep my idea but I don't want to players to be turned off by poor performance, it's like they would be getting punished for doing good in the game. I've already made it a point to stay away from convex mesh colliders, all of my colliders are compound colliders or just a single primitive. I appreciate any suggestions, thanks.

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 vexe · Oct 06, 2013 at 08:45 AM 0
Share

Are you handling any physics inside Update? If so then switch to FixedUpdate - which is meant for physics/rigidbody-related stuff. - It's a bit hard to tell what's causing the drops since you didn't show us any code. If you're on Unity Pro use the profiler to identify the bottlenecks.

avatar image feneq · Oct 06, 2013 at 09:18 AM 0
Share

Hey thanks for the reply. I would have showed code if I thought it would help. There really isn't anything to show as there really isn't any physics based code. Perhaps there should be though, that's kind of what I'm trying to figure out. Perhaps there is a technique I don't know when dealing with many active rigidbodies. It seems unlikely though. The game is about stacking objects of varying shapes, the tower of objects that is placed is constantly shaking and even swaying as the player builds. It's decently fun to play but as you might imagine, the higher the player stacks the larger the impact on performance.

avatar image vexe · Oct 06, 2013 at 09:34 AM 0
Share

do you really need all the stacked objects to be active at the same time? - if not, then you might consider disabling those you don't need.

avatar image pako · Oct 06, 2013 at 09:51 AM 0
Share

In my opinion, the only way to prevent the decrease in performance is not to use a rigidbody for every stacking object.

$$anonymous$$aybe you could think about having a rigidbody to the whole stack and a rigidbody to the last object added to the stack. In other words, simplify the physics of all previously added objects to a single "accumulative" object, and then have that, interact with newly added object that will also have a rigidbody attached, for the sake of interaction, and then removed after its effect has been accumulated on the main stack.

Hope this helps.

avatar image feneq · Oct 06, 2013 at 04:53 PM 0
Share

Hey thanks guys. I agree, it's looking like I need to start grouping or manipulating the objects in some way. I'm not sure about a singular accumulative object for my game but this really does help push me in the right direction. I'm thinking I'll group the objects in chunks but do it in a way that the number of chunks never exceeds a certain threshold. I'll have to play around with the idea.

Show more comments

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by salex100m · Nov 17, 2013 at 06:05 PM

Hey, I just ran into this same problem. My code isn't quite complete so my GOs are all congregating on top of each other. When more than 4 end up at the same position, they game slows down to mud. It isn't related to the number of objects either because if they are not stacked, the game runs fast.

I strongly suspect it is because each object has a mesh collider attached and those colliders are triggering themselves up the wahoo when they are stacked.

I suggest you turn off collision and triggering if possible when your items are stacked. After all, collisions are intended to bounce objects off each other.

Let me know if that worked.

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 Bunny83 · Nov 17, 2013 at 06:11 PM 0
Share

Yes, that is the problem. I just saw this question got bumbed but i didn't see any new post, so i checked the moderation queue and i've fould your answer ;)

The problem when you stack several physics objects they push each other all the time. A single impulse could go several times up and down through the whole stack.

If your game mechanics allows it, just "disable" single elements when they come to "rest" by setting is$$anonymous$$inematic to true or by destroying the Rigidbody component.

avatar image salex100m · Nov 17, 2013 at 07:07 PM 0
Share

I'm currently looking at this issue, like I said. I've counted exactly five objects can stack with no visible fps lag. As soon as I add a 6 object, it goes to hell.

If you turn off "is Trigger" then they just bounce off each other.

If you want to stack them, just forget the physics colliders and maybe just check the difference from the transform.position of each object. If the object's center point is very close to another object's they are stacked right?

avatar image
0

Answer by meat5000 · Oct 06, 2013 at 10:24 AM

Set Fixed TimeStep to 0.01 in Time Manager.

Consider:

 function OnCollisionEnter()
 {
    //if collision object is stackingObject
    //Parent Object
    //Make Kinematic
 }
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 Jamora · Oct 06, 2013 at 02:09 PM

The problem could also be because of excessive draw calls. (Check the stats window in the Editor, next to Maximize on Play.) If the number for draw calls increases every time you add an object, you will need to consider sharing materials.

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 feneq · Oct 06, 2013 at 04:39 PM 0
Share

Hey thanks for the input. I am using shared materials, my game stats look pretty good and the draw calls are never over 10 so far.

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

21 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

Related Questions

Are my kinematic rigidbodies slowing my scene down? 2 Answers

Raycaste vs trigger Colliders & Rigidbody performance 1 Answer

Physic processing takes a lot of time for one rigidbody 1 Answer

Rigidbody Overhead 1 Answer

Best way to move a rigidbody 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