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 Inv · Jul 09, 2017 at 03:26 AM · collisionphysicsphysics2dhitbox

Set ContactFilter2d to not use child object's triggers.

In our player's GameObject, we have a collision box to track the player's collision, as well as a trigger in a child object that activates when using an attack. To get the movement we wanted, we followed Unity's 2d platformer physics tutorial which can be found here: https://unity3d.com/learn/tutorials/topics/2d-game-creation/intro-and-session-goals?playlist=17093

Everything works fine until we enable the child's trigger. After some degugging, I believe that the ContactFilter2D is using the child object's trigger as a collider as well. Is there any way to get around this, or will I have to place the triggers in a object that is not a child of the player?

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

2 Replies

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

Answer by OmegaJeff · Jul 17, 2017 at 11:20 PM

This is definitely a Unity bug with both the ContactFilter2d and RigidBody2d.Cast(). The main issue seems to be that RigidBody2D.Cast() is including the child triggers as part of the object's overall collider shape, and there is no override option in the function itself to tell it not to do that.

We managed a two step work around, but it isn't perfect and we won't be relying on Rigidbody2d.Cast() for anything else until it's fixed.

The first step is to manually set the LayerMask for the filter to exclude any layers you're using for triggers.

The second step is to have the actual trigger collider and any OnEnter/Stay/Exit scripts stored in an object outside the rigibody's hierarchy, then use a placeholder child in the hierarchy. Set up a simple script on a child of the rigidbody to pass its transform values (and any other values like enable, offset, size, etc...) to the external object. If you're using scale flipping, be mindful to offset the position by the reference object's scaled local position.

Comment
Add comment · Show 4 · 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 Inv · Jul 18, 2017 at 05:35 PM 0
Share

Reassuring to hear that its a Unity bug and not just us using ContactFilter2D incorrectly. We have been working at the problem as well, and are pretty much on the same path you described. It's a bit frustrating that we have to handle it this way, but for now it's our only real option as long as this bug exists. Thanks for the answer!

avatar image MelvMay ♦♦ · Apr 19, 2018 at 02:36 PM 1
Share

This is the first I've heard of this and no bug has been submitted either. This is why bugs are not fixed; because many people leave it up to others. I'll check it out but I'd also appreciate a bug report if possible.

avatar image OmegaJeff MelvMay ♦♦ · Apr 19, 2018 at 10:40 PM 0
Share

Hello. I actually did submit a bug report for this, around the same time I wrote this initial workaround back in July 2017. The case number was 932584, and this is the developer response I was forwarded via support:


Rigidbody2D.Cast() will sweep all attached Collider2D on the Rigidbody2D so yes, it's by design. That said, for some users who want to ignore any attached Collider2D set to be triggers, we should probably add that as an option so this is more a feature request and not a bug. The ContactFilter2D option (mentioned in the case) set to not use triggers refers to Collider2D being detected, not the Collider2D being swept i.e. should we detect triggers or not.

Note that Rigidbody2D.Cast() is simply a convenience function. The user can easily use the following features to grab all the attached colliders: https://docs.unity3d.com/ScriptReference/Rigidbody2D-attachedColliderCount.html https://docs.unity3d.com/ScriptReference/Rigidbody2D.GetAttachedColliders.html

They can then iterate them perfor$$anonymous$$g Collider2D.Cast on each, ignoring any that are triggers: https://docs.unity3d.com/ScriptReference/Collider2D.Cast.html


Thank you for looking into this.

avatar image MelvMay ♦♦ OmegaJeff · Apr 20, 2018 at 08:31 AM 0
Share

Thanks! So I follow now, afraid I read your problem wrong above. I thought you meant that the Rigidbody2D.Cast was causing colliders attached to that body to contact other (trigger) colliders on the same body, something which is explicitly checked for. $$anonymous$$y bad.

I see now that you meant not using trigger colliders on that body as part of the sweep. I do recall that case and it was me who gave that message to the QA to reply. On our internally planning board there is a card amongst many small Rigidbody2D features, this is one but it's not yet been implemented, effectively providing an option to control whether triggers should be used or not as part of the sweep.

I've got a list of 9 low-hanging fruit items to be implemented in the next few months, I'll make a promise here to add that to the list. Sorry for the inconvenience.

I believe the workaround above though pretty much does what Unity will do anyway i.e. iterate all colliders on the body, ignore any triggers and perform a Collider2D.Cast on each and use all the results or only the closest depending on what you want.

avatar image
0

Answer by SebaLagos · Apr 06, 2018 at 05:30 PM

Is this fixed or still happening @OmegaJeff ? we are on the 2017.4.0f1 and still happening, even with the manual setup of the layermask

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 OmegaJeff · Apr 06, 2018 at 11:06 PM 1
Share

Looking at the documentation, I don't think they've made a change but I haven't tested it.

We did find a quicker/easier/less complicated workaround though.

Create a reference to your Collider2d in the script, and then use Collider2d.Cast() ins$$anonymous$$d of Rigidbody2d.Cast(). It will cast only the referenced Collider2d, and it wont return hits against any children of the Rigidbody2d. It's a bit cleaner if you want to keep the Rigidbody2d at the top of the prefab's hierarchy.

avatar image MelvMay ♦♦ · Apr 19, 2018 at 02:42 PM 0
Share

Can you please submit a bug report.

Thanks.

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

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

Related Questions

Unity Physics Collision Execution Order Error? 1 Answer

Executing code on touching edges of a collider from the inside 0 Answers

Trigger is not executed 1 Answer

Reset Rigidbody2D rotation after collision 2 Answers

Precise Collision Detection with Rigidbody2D.Cast 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