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 mallardz · Oct 22, 2014 at 03:13 PM · collisioncollision detectionlayers

Why is OnCollisionEnter2D called when it's layer's collisions are being ignored?

I'm sure this is down to my lack of understanding of the unity physics system.

I'm trying to implement a simple one-way platform for a 2d game (based on character y velocity) but have got stuck on creating a reliable way to let the character 'drop down' from a platform on pressing the down arrow.

While trying to debug and whittle down the code, I've found myself with this strange debug script:

 using UnityEngine;
 using System.Collections;
 
 public class DebugPlatform : MonoBehaviour 
 {
 
     void OnCollisionEnter2D(Collision2D other)
     {
         if(Physics2D.GetIgnoreLayerCollision (other.collider.gameObject.layer, this.gameObject.layer))
             print ("ERROR: How does this happen?!!");
         else 
             print("This is normal.");
      }
  }

When I place this on my one way platform and mess about in game, sometimes the character refuses to drop down on command, and the error message is printed.

From what I understood, GetIgnoreLayerCollision returned whether the collisions between the layers were being ignored or not.

So my questions are:

  • Why is OnCollisionEnter2D being called even though the layers are supposed to be ignored?

  • Is this ignore value just a request, not absolute? Maybe some collision optimization that I have to override?

  • I can't imagine this is some multi-threading issue, as the error appears regularly, after I do a normal jump on the platform.

  • Am I doing something completely wrong?

Comment
Add comment · Show 3
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 Baste · Oct 22, 2014 at 04:04 PM 1
Share

From what I can see, this really, really looks like a bug. Unless someone spots something I can't, you should probably post a bug report.

avatar image mallardz · Oct 23, 2014 at 07:03 PM 0
Share

@Baste Noooooo... I had high hopes for IgnoreLayerCollision. I was sure I was just doing something stupid. In the meantime I've figured out another way to implement this, just requires an extra platform specific collider.

avatar image Ed unity · Oct 23, 2014 at 09:11 PM 0
Share

@mallardz Your code appears to be good. This is most likely a Unity error as Baste suggested. Please file a bug report with clear reproducible steps and a repro project. Thanks.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by b-cancel · Feb 20, 2017 at 09:42 AM

Here I am hoping that someone told you about the platform effector 2D and that you didn't waste time coding this flawlessly... or... since this is from 2014 that it existed...

My platform currently is a little different that the regular platform unity has created for us... but i simply applied my modifications on the platform effector 2D...

For those who wandered here now 3 years later... THIS BUG HAS BEEN FIXED...

This is exactly the code that I am using to allow drop downs from the platform that the standard platform effector 2D creates

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Physics Collision Layer Programmatically. 0 Answers

Why wont OnCollisionEnter2D work? 1 Answer

Unintentional Occasional Collision 1 Answer

Change NavMesh Speed after collision/trigger just for 1 object 1 Answer

OnCollisionEnter not working with CharacterController 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