Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Unity 2D (trigger) box colliders not working on 5.3?

Discussion in '2D' started by MartinIsla, Dec 8, 2015.

Thread Status:
Not open for further replies.
  1. tedthebug

    tedthebug

    Joined:
    May 6, 2015
    Posts:
    2,570
    (Case 752947) OnTriggerEnter2D & OnCollissionEnter2D

    Smallest file I could do.
    1. Background has a kinematic rigidbody & a box collider at the bottom edge that is set to be a trigger
    2. unicorn has a small box collider not set as a trigger
    3. falling objects have circle colliders & no rigidbody.
    None register & all objects keep falling past the colliders

    Thanks for looking into it, hope you get to enjoy your break at some point.
     
  2. E_Urban

    E_Urban

    Joined:
    Sep 16, 2014
    Posts:
    8
    I'm also experiencing these same problems which were not in 5.1, but are in 5.2 and 5.3.

    Even with a kinematic rigidbody2d attached...
    OnTriggerEnter2D will not register with scaling objects.
    OnTriggerEnter2D will not register if moving by being child of a moving parent.

    Is it not recommended to move a trigger by parenting to a moving object? Should I always un-parent and create a script that uses MovePosition()?
     
  3. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,316
    Bug has already been fixed against 752059. This also fixes 752947.

    752764 is odd. It sounds like the same problem but doesn't seem to be resolved by the fix. Unfortunately it's a huge project and not a simple reproduction case which doesn't help. It also won't load on 5.2.3f1 so I can't verify how it's supposed to work there either. Maybe it's related to a known issue when objects are continually scaled, not sure yet.
     
  4. abekert

    abekert

    Joined:
    Nov 12, 2014
    Posts:
    2
    Confirming this one. The character has a RigidBody2D and is moved by AddForce. Another objects are static. Character changes his scale (and collider radius) every frame.
     
  5. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,316
    Yes, the continuously scaling case is a separate issue. I already have two cases reported for this issue which is being looked at now.
     
    AGSMarcinDraszczuk likes this.
  6. tedthebug

    tedthebug

    Joined:
    May 6, 2015
    Posts:
    2,570
    Thank you. Have a merry Xmas & enjoy your break.
     
  7. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,316
    Thanks! I deferred my leave until this is sorted. I'm sure even saying that will anger someone. :(
     
    Nilaakash and majman like this.
  8. Cuicui_Studios

    Cuicui_Studios

    Joined:
    May 3, 2014
    Posts:
    72
    We have spent the morning working on the issue.

    And we figured out some things :
    • TriggerEnter2D doesn´t work properly, but the same code used on a TriggerEnter2D works perfectly on a TriggerStay2D
    • Objects with movement and changing scale each frame always skip the Enter2D trigger when colliding with static ones
    • A character with a Trigger Collider moved by mouse drag only collides properly with objects when is moved fast towards them or is static and not being clicked. When we make it stand still AND still clicking on it still skips the trigger.
    Any estimations on when the fix is going live? I believe those might fix our issues as well. If you need the copy of the project on 5.2.x or a video of it working, we can provide them.
     
  9. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,316
    The scaling issue is a completely separate one to the fix already in progress; that's being looking at now (I have two other cases reporting that). Seems like you maybe seeing both issues but I just can't tell.

    Note that both issues were not present in 5.2.3f1 but are present in 5.2.3p1. Unfortunately they're being associated as being introduced in 5.3.0f4

    We have to do some complex stuff behind the scenes because when you modify collider geometry, the whole shape needs recreating (Box2D creates immutable colliders). This causes contacts to be destroyed and recreated later and they have to be matched-up with the old ones to keep the Unity Enter/Stay/Exit state. It's a real pain to have to do and hinders performance and is easy to break. The suite of tests we have didn't cover this but now it does. I can verify that by scaling continuously (each frame), the original 'Enter' is replaced by 'Stay' so that's why you see 'Stay' and not 'Enter'.

    There's due to be a rewrite of portions of the Box2D we use in Jan 2016 to make this not only perform better but also stop this callback madness.

    In the meantime, a fix for this 'scaling' issue is in progress.
     
    Last edited: Dec 11, 2015
  10. studentsimf

    studentsimf

    Joined:
    Dec 18, 2014
    Posts:
    4
    Maybe it will help someone.
     
  11. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,316
    The scaling issue has now been resolved. I have verified this on cases 752764, 752215, 752570 & 748455.

    This bug has been with us since 5.2.3p1.

    Sorry for the problems this has caused. I am now getting this running on our build farm then into the patch release stream.
     
    Naamani, theANMATOR2b, -chris and 4 others like this.
  12. kvadd

    kvadd

    Joined:
    Aug 8, 2013
    Posts:
    3
    Awesome work MelvMay!
     
  13. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,316
    Note that these two fixes are going into 5.3.0p1 and 5.2.4 at the same time so should cover all 5.2 and 5.3 users equally.

    Again, sorry for all the problems this may have caused.
     
  14. Volcanic-Penguin

    Volcanic-Penguin

    Joined:
    Feb 7, 2013
    Posts:
    9
    Thanks MelvMay!
     
  15. georgeq

    georgeq

    Joined:
    Mar 5, 2014
    Posts:
    662
    Case 753198:

    If an animation is being played which affects the collider position/rotation, OnCollisionEnter2D is simply never called, no matter if you have a RigidBody2D attached or not. By disabling the animator controller OnCollisionEnter2D is called, just a little latter than it should be, but the trigger works. In my case to get rid of the animation is not an option.

    @MelvMay I think you should check all possible ways in which a collider can be moved, rotated and scaled, not always is due to an explicit script call.
     
  16. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,316
    Not sure why I need to do that. Fundamentally, the issue was that if you do something that causes the collider to be recreated, this was the problem. Unfortunately, Unity is very open and allows you to change almost every property but it's using Box2D that doesn't actually allow that so the underlying collider needs to be recreated.
     
  17. dendriel

    dendriel

    Joined:
    Aug 6, 2015
    Posts:
    3
    Hi!

    I had the same issue being discussed in this topic. I fixed the problem by using the (expected) approach that MelvMay commented in some of his replies. That is attaching a kinematic Rigidbody into the object that contains the trigger collider (in my case, a Collider2D and Rigidbody2D).

    Regards,
     
  18. The-Mighty-Git

    The-Mighty-Git

    Joined:
    Oct 8, 2014
    Posts:
    3
    "the original 'Enter' is replaced by 'Stay' so that's why you see 'Stay' and not 'Enter'."​

    Adding kinetic 2d rigidbodies fixed some of my issues, but it was using the above info I made my moving triggers (bullets) work again by treating 'OnTriggerStay2D' as an 'OnTriggerEnter2D'.

    Thanks everyone here, without this thread I would have thought I was going nuts :)
     
  19. chdrvn

    chdrvn

    Joined:
    Dec 4, 2013
    Posts:
    23
    I have a box collider2D without a rigidbody as a child of an object which has both, and Im moving the parent by setting the velocity. The child object no longer registers triggers in 5.3. Would this be considered moving a static collider "the wrong way"? When I first read about that rule I assumed it was only when you set the transform.position.
     
  20. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,316
    A static collider is a collider that isn't attached to a Rigidbody2D component. If the parent has one then it's not a static collider but is either a dynamic or kinematic.
     
    Last edited: Dec 17, 2015
  21. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,316
    5.2.4 and 5.3.1 have been released which solves the bugs that were submitted. Hope you can all now move forward with your projects.
     
    -chris, MrEsquire, abekert and 2 others like this.
  22. tedthebug

    tedthebug

    Joined:
    May 6, 2015
    Posts:
    2,570
    Woohoo, thanks heaps. I was needing these for the silly game jam.
    @MelvMay are any of you guys going to enter it? We are trying to think of a prize category for unity employees & mods.
     
  23. tedthebug

    tedthebug

    Joined:
    May 6, 2015
    Posts:
    2,570
    I've just checked for updates & it says there are none, I'm currently on 5.3.0f4.

    Is there a delay before it is available for download?
     
  24. TanselAltinel

    TanselAltinel

    Joined:
    Jan 7, 2015
    Posts:
    190
    They are available, you can get them from here: http://unity3d.com/get-unity/download/archive
    5.3.1 and 5.2.4 listed there.

    I just checked and this seems to be solved. Thanks a lot, now I can move on with my project :)
     
    tedthebug and MelvMay like this.
  25. Volcanic-Penguin

    Volcanic-Penguin

    Joined:
    Feb 7, 2013
    Posts:
    9
    Well, seems like at least I'm still having an issue.

    I've updated to Unity 5.3.1f1.

    In my scene I have a GameObject with a Collider, a RigidBody2D, and a script with an OnTriggerStay2D.
    I have another GameObject with a Collider, a RigidBody2D, and an Animator component that is animating the scale of the GameObject.

    The collision is working great in the Editor. However, when running it on Android (Version 4.0.4 if that matters) the scaling animation is making the collision glitch. The OnTriggerStay2D is being triggered every single frame, even when the object is off-screen.
     
  26. tedthebug

    tedthebug

    Joined:
    May 6, 2015
    Posts:
    2,570
    I just downloaded the new version (5.3.1f1) & the triggers are working but not the OnCollisionEnter2D. The balls have NO rigidbody2D & but do have circle2D colliders, the player has a rigidbody2D (kinematic) & a box2D collider. Neither collider is a trigger. The player isn't moving & the balls fall using transform.translate (since they don't have a rigidbody). They pass through the player & breakpoints that I set on the collision if statements aren't registering.

    The ground has a rigidbody2d & a trigger collider & they are working fine.
     
  27. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,316
    As per the docs, kinematic only ever contact dynamic colliders and never other kinematic or static ones. Kinematic do report triggers.

    Every bug that was reported was tested several times over from initial fix to final build. If you still have a problem then please let me know the bug report or please send me the case number.

    It would be nice if we didn't keep adding to the same thread either; the topic of the thread is related to static triggers.
     
    Last edited: Dec 21, 2015
  28. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,316
    OnTrigger2D stay won't ever be reported per-frame but per fixed-update. Being on-screen or off-screen has nothing to do with physics. 'Making the collision glitch' isn't very informative; what does that mean? If you are constantly animating the collider then it won't ever sleep hence it'll keep reporting 'stay' callbacks whilst its awake. Personally I would avoid using 'stay' callbacks because they are so frequent and they are only sent whilst the body is awake.
     
    Last edited: Dec 21, 2015
  29. abekert

    abekert

    Joined:
    Nov 12, 2014
    Posts:
    2
    Now colliders work as supposed! Thank you :)
    New bugs ariived. I'll wait for another week.
     
  30. Volcanic-Penguin

    Volcanic-Penguin

    Joined:
    Feb 7, 2013
    Posts:
    9
    Does this include being tested on Android?

    With "even when the object is off-screen" I mean that even when the two objects are very far away from each other the game still thinks that they're colliding. The OnTriggerStay2D code (checking for correct tag on the Collider GameObject) is running as if they are touching every fixed-update. If I switch to OnTriggerEnter2D, the collision code runs once as soon as the game starts up even though they are not colliding. If I turn the Animator component off, so that there is no scaling animation, the collisions work as they should, i.e. collisions occur only when objects touch each other.

    This problem is only happening when running the game on Android (my phone has Android 4.0.4) and works as it should in the Editor.

    If I'm the only one having this issue then I suppose I'll have to make sure I can reproduce it in an empty scene and send in a bug report.
     
  31. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,316
    You should submit a bug report but really, it doesn't sound like anything that this thread is about. Sounds like the animation is moving the objects so that they overlap but without a bug report, it's hard to know.
     
  32. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,316
    Your problem wasn't tested on Android because you don't have a case number nor do we even know what the issue is, when it started or if it's limited to Android.

    Reporting issues with bug reports is the only way to determine if your issue is already known and has been resolved.
     
    Last edited: Dec 21, 2015
  33. Volcanic-Penguin

    Volcanic-Penguin

    Joined:
    Feb 7, 2013
    Posts:
    9
    I would know if the objects are overlapping because of the animation. They're not, the scaling animation is very minimal and the objects are very far apart.

    Yes but there have been two bug reports about continuous scaling making collisions not work (seems related) so I was wondering if those fixes have been tested on Android. The issue was not present in Unity 5.2.0
     
  34. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,316
    The fixes reported and resolved all had unit-tests added to support them which run on ALL platforms. This suggests that your problem is something else.

    The issues reported were generated in 5.2.3p1 not 5.3.0f4 which is why the same fixes went into 5.2.4
     
  35. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,316
    The reported issues weren't about getting reports when objects were (apparently) not overlapping on Android but simply about not getting 'enter' callbacks.

    If you're saying this is the problem you had originally then you should've submitted a bug report. None of this is helping you though so if you can do that now then the issue can be looked at.
     
  36. Volcanic-Penguin

    Volcanic-Penguin

    Joined:
    Feb 7, 2013
    Posts:
    9
    The problem I had originally was the same as others in this thread. But in attempting to work around those problems I changed some things which made me stumble upon another issue.

    Anyway, as I have previously stated, I will submit a bug report.

    Cheers and Merry Christmas.
     
    MelvMay likes this.
  37. tonzot

    tonzot

    Joined:
    Jan 11, 2016
    Posts:
    2
    my problem is that the OnTriggerEnter2D function gets automatically called when starting level one. (In the android build)
    in the editor everything works perfectly. On android the character isnt even hitting the trigger and this problem happens the character cant even move and all OnTriggerEnter2D Methods are called.
     
  38. tonzot

    tonzot

    Joined:
    Jan 11, 2016
    Posts:
    2
    Hello, my problem is that my ontriggerenter2d functions start without any reason after the build ofr android on windows everything works perfectly so can I send you my project and you could look at that bug ? It would make me very happy because Iam trying to solve this bug for over 3 weeks and it just wont work.
     
  39. SavedByZero

    SavedByZero

    Joined:
    May 23, 2013
    Posts:
    124
    Oddly enough, I'm working in Unity 5.3.1f and using Collider2D/RigidBody2D without a problem, but the project manager who's running it in Unity 5.2 is having a bug where colliders don't do what they're supposed to (he's dragging some gems to the boxes that absorb them, which has always worked fine on my end, but when I commit the build and he pulls it down in Unity 5.2, it doesn't work for him)

    [EDIT]: he updated to 5.3.1, and that fixed the problem.
     
    Last edited: Jan 29, 2016
  40. CoolCasualCat

    CoolCasualCat

    Joined:
    Jul 7, 2015
    Posts:
    2
    I just updated Unity to 5.3.2f1 and TriggerEnter/Stay/Exit2D still doesn't work.
     
  41. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,316
    I think there would be a lot more shouting if those callbacks just didn't work and TBH saying just that is completely unhelpful. If you have a bug then please report it with a simple reproduction case rather than just posting on a thread like this assuming it's the same problem.
     
  42. grosssmutttr

    grosssmutttr

    Joined:
    Apr 15, 2014
    Posts:
    168
    Upgraded to 5.3.3 and tested the OnCollisionEnter2D. Unfortunately it doesn't trigger always as in the version we used before. Sadly we don't know since which version this behaviour is present but it worked with 5.1...

    Submitted a report: (Case 774128)

    Hope this will be fixed soon :D

    I already created another thread which I think was a mistake because this one meets perfect:
    http://forum.unity3d.com/threads/sqrmagnitude-changed.388167/
     
  43. cjafet

    cjafet

    Joined:
    Mar 2, 2016
    Posts:
    1
    Hi guys! I have also tried all the suggestions and could not make it work either, but i find a way out that i would like to share. My solution was to create a separated script in javascript and call the onTriggerEnter2D there. In js the function is working and i could finally move ahead! Maybe it help someone out as well!

    #pragma strict


    function Start () {

    }


    function Update () {

    }

    function OnTriggerEnter2D (Col: Collider2D) {

    if (Col.CompareTag("Player")) {

    Debug.Log ("Enter on Trigger");

    Destroy (this.gameObject);
    }

    }
     
  44. simone9725

    simone9725

    Joined:
    Jul 19, 2014
    Posts:
    234
    how fix this ? On unity 5.3.3 it still exist
     
  45. BAnyBudde

    BAnyBudde

    Joined:
    Jun 3, 2014
    Posts:
    51
    I thought I had the same issue, until I realised that my collision matrix in Edit/Project Settings/2D Physics was changed before I updated, make sure thats not the issue.
     
  46. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,316
    Previously reported bugs were fixed and verified by QA

    If you have a problem then please report a bug; don't just assume a previously reported issue is the same as yours because it sounds similar.
     
  47. fishg

    fishg

    Joined:
    Jul 25, 2014
    Posts:
    90
    This bug is come back in unity 5.3.4p5.
     
  48. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,316
    There were no changes to 2D physics in 5.3.4p5 so by 'This bug' I presume you have a problem and the title of 'unity-2d-trigger-box-colliders-not-working' describes your problem accurately. If not, which bug are you referring to specifically.

    Just submit a bug report.
     
  49. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,316
    As with others in this thread, it's being used to describe different problems as 'this' bug. If you came here to get a bug fixed then please, please submit a bug report and stop posting here waiting for some fix.
     
    TanselAltinel likes this.
Thread Status:
Not open for further replies.