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 Simon Says · Sep 12, 2014 at 08:39 PM · triggerphysics2dcollider2d

Moving many 2D triggers is slow. Why?

Hi, I've got a scene with about 1600 2D colliders set as triggers and a rigidbody that is disabled. The problem is: when I move all triggers at once, it takes too much time on the main thread.

To clarify, actually moving the responsible GameObjects (changing transforms) takes about 13 ms when profiled. But at the same time, the movement is noticeably sluggish and the basic Game View Stats report around 120 ms. So clearly there's something going on behind the scenes. I strongly suspect Physics2D is the culprit here, because when I disable half of my triggers, the performance improves rapidly (to 40 - 50 ms).

Is there any way to bypass these extraneous physics computations? I really need only trigger detection.

Comment
Add comment · Show 5
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 contab009 · Sep 12, 2014 at 10:36 PM 1
Share

Try to make sure the colliders are primitive shapes. Edge/Polygon colliders are more expensive. Other than that, nothing without disabling some colliders comes to $$anonymous$$d.

avatar image rutter · Sep 12, 2014 at 11:34 PM 0
Share

Do you really need to move 1000+ triggers in one frame? There might be a more lightweight means of achieving a similar effect. You might disable some of those colliders when they're not being used. You might distribute the move over several frames. You might write up some math that reduces the check complexity.

Also, are you seeing any messages in your console window? Either warnings/errors, or even messages you log out yourself. Some messages might indicate problems (like moving static objects), but another consideration is that each message takes several milliseconds to print.

avatar image Simon Says · Sep 13, 2014 at 01:51 PM 0
Share

@contab009 All shapes are either rectangles or circles. Vast majority are circles.

@rutter The thing is nothing I do in the code is just so expensive. I took a good deal of time to check everything. It's what happens on the Unity side that causes the overhead. I guess rearranging some sorting queues and maybe some preli$$anonymous$$ary physics computations I'm not aware of. So I don't know how would simplifying math on my side help short of re-writing the whole trigger subsystem myself. Also, there are no warnings or errors and objects are not static (I checked).

One thing you're both right about. I could disable most of the colliders before moving en masse and re-enable them afterwards. It will probably cause some delays at start and finish, but they'll probably be acceptable. Thanks for the idea. It's kind of obvious, but I guess I needed to hear it from someone else.

avatar image screenname_taken · Sep 13, 2014 at 02:13 PM 0
Share

If the triggers have a rigidbody2d set as kinematic, does it make any difference?

avatar image Simon Says · Sep 13, 2014 at 07:27 PM 0
Share

@screenname_taken There's no rigidbody involved. It's disabled during the operations and yes, it's set as kinematic.

Anyway, I disabled all unnecessary colliders during movement and it works like magic! Thanks everyone for input!

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Simon Says · Sep 13, 2014 at 08:06 PM

All right, I didn't manage to figure out the exact cause behind all this. But even if I did, most probably I couldn't have done anything about it. It's hardwired in Unity.

The bottom line is: don't move so many primitive 2D shapes at once as a part of continuous interaction or even real-time updates. Unity cannot handle it smoothly. My experiments show that about 500 simple triggers are barely manageable on a modern PC, giving close to 30 FPS.

My solution was to disable as many colliders as possible before performing the movement. It might not work for everyone. You might want to distribute movement across several frames as @rutter proposed, or simulate rapid movement of many objects in your script data and then apply it less frequently. Other than that there aren't many options but to write your own trigger management system, bypassing Physics2D.

This was experienced in Unity 4.5.2 and 4.5.4.

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

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

Related Questions

Collision with instantiated non-moving objects. 1 Answer

OnTriggerExit2D Does not work 1 Answer

Physics2D.OverlapCircle dont detect triggers 3 Answers

OnCollisionEnter fires, but OnCollisionExit does not 1 Answer

Update scaling and 2d collider/trigger not firing 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