Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Tocseoj · Dec 22, 2015 at 09:05 AM · rigidbody2dcolliderscollider2d2d-physicscollider 2d

Static Colliders in the 2D Engine in Unity 5

So in Unity 5, there was a change to how static colliders work in the 3D Engine, the patch notes reading

  •  Moving static colliders does not cause performance penalty anymore.
    

But because 2D physics use a separate engine, does moving (or in my case changing them by switching isTrigger on and off) static colliders in 2D still cause performance issues?

And to address my issue of toggling isTrigger on and off, should I use a kinematic Rigidbody? (Assuming changing static colliders still have performance issues) As I have a lot of these colliders, so if I don't need the extra Rigidbody calculations, that would be great.

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
1
Best Answer

Answer by MelvMay · Dec 22, 2015 at 10:02 AM

I implemented the 2D physics in Unity and one thing I really don't like is that not adding a Rigidbody2D means all colliders are static. This gives the false impression that they are somehow better without one and that adding one is worse.

The actual fact is that by not adding a Rigidbody2D component (which just attaches the colliders to a dynamic/kinematic body), the colliders are instead adding to a static body which is created implicitly. In other words, colliders are always added to a body.

Don't move a static collider, it has a penalty in 2D; attached it to a Kinematic body.

Toggling trigger on/off doesn't really have a bearing on the above. Know that like many other properties you change on colliders/rigidbody, the collider/rigidbody is being recreated completely behind the scenes; Box2D is mostly immutable in that it allows you to set things up but not change them; only the obvious things are allowed to change. Changing a collider IsTrigger causes a recreation (it's called a sensor in Box2D).

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 Tocseoj · Dec 22, 2015 at 06:36 PM 0
Share

Would creating (Instantiating) a new collider and then destroying it be faster/more efficient than toggling isTrigger on and off?

Also, these are PolygonCollider2Ds, does that make a difference with it being immutable?

avatar image MelvMay ♦♦ Tocseoj · Dec 22, 2015 at 07:17 PM 0
Share

It wouldn't be faster no. $$anonymous$$odifying PolygonCollider2D can be very expensive because it's not a primitive collider, it's an outline (or outlines) decomposed into multiple primitives, all of which have to be recreated.

Really don't understand why you'd want something to be a trigger then not a trigger.

If you just don't want it to collide with anything then the absolute fastest way is to use: Rigidbody2D.simulated which just deactivates the body and its colliders, joints and contacts. Doing this doesn't require recreating colliders, it's just internally ignored inside Box2D.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

(2D) Can't use colliders when I have a kinematic rigidbody? 1 Answer

Tilemap Collider 2D preventing objects from moving 2 Answers

Polygon Collider 2D doesn't have the "edit collider" button avaliable. 0 Answers

CircleCollider2D vs PolygonCollider2D: which collision solving is less expensive? 1 Answer

Moving colliders that are part of a composite collider 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