Search Unity

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. MartinIsla

    MartinIsla

    Joined:
    Sep 18, 2013
    Posts:
    64
    Hi! I just updated to Unity 5.3. I find the new features amazing.

    I was building this 2D game for an event I'm going in 5 days. It was almost finished (code worked perfectly, I only had to import the animations), but now triggers are not working!

    There's a wave following the player. If it touches you, you die. That simple.

    I attached a script with this code in it:

    Code (CSharp):
    1. void OnTriggerEnter2D(Collider2D col)
    2. {
    3.    print("Are you even colliding my friend?");
    4.    if (col.gameObject.tag == "Player")
    5.    {
    6.        print("Working?");
    7.        //Do stuff
    8.    }
    9. }
    As you see, I added the "print" lines to test if it was colliding (tried changing them to Debug.Log just in case "print" was not working anymore for some reason, but it's the same), but they're not showing at all.

    I realised it works if I move. It only fails if I just wait for the wave to touch me. I think it's a Unity problem as that's the way I always tested the wave.

    Is this a Unity bug?

    Thanks
     
    Last edited: Dec 9, 2015
    parks1218743 and majman like this.
  2. georgeq

    georgeq

    Joined:
    Mar 5, 2014
    Posts:
    478
    I'm having a the same issue. Under Unity 5.1 I have no problems with OnTriggerEnter2D, everything works just right!!! However after I upgraded to version 5.3 OnTriggerEnter2D is not longer called all the times. Not sure yet, but for the way my game behaves I think OnCollisionEnter2D is not being called every time it's required.

    This is starting to get frustrating, every single version since 5.2.0 has had issues that prevent me from upgrading and I end up having to downgrade back to 5.1. 5.2.0 was buggy as hell, 5.2.1 and 5.2.2 had lots of severe performance issues, 5.2.3 solved most of the issues, but still was too slow on Android to take it seriously. 5.3 seems to have solved all the performance issues of the 5.2 series, but now it doesn't behave properly on collisions, so for the fifth time in a row, I'm on my way to downgrade to 5.1.
     
    parks1218743 likes this.
  3. MartinIsla

    MartinIsla

    Joined:
    Sep 18, 2013
    Posts:
    64
    As my game is really small and the bug only affected the main character, I made something that makes me cringe:

    Code (CSharp):
    1. rb.AddForce(new Vector2(1, 0) * Time.deltaTime * 0.000000001f);
    The guy who tought me saw this, he would hit me hard in the face and kill himself.

    EDIT:
    He just saw it. He said we wouldn't hit me... because "that's for noobs". He said he would electrify me until I learn.
     
    Last edited: Dec 9, 2015
  4. Ankka

    Ankka

    Joined:
    Mar 26, 2014
    Posts:
    1
    Same problem here! Updated from 5.2 to 5.3, and now it doesn't always register OnTriggerEnter2D.
     
  5. studentsimf

    studentsimf

    Joined:
    Dec 18, 2014
    Posts:
    3
    I have the same problem! what to do?
     
  6. Manny Calavera

    Manny Calavera

    Joined:
    Oct 19, 2011
    Posts:
    205
    Is the object with the trigger by any chance missing a kinematic Rigidbody2D?

    If that's the case, add a Rigidbody2D to your object, check 'Is Kinematic' and the trigger events should start registering promptly.

    --

    There is a noticeable delay now in 5.3 when you move a static trigger (which you shouldn't be doing, anyway). I've noticed the change in behavior during beta and posted about it here.
     
  7. Bunderant

    Bunderant

    Joined:
    May 29, 2013
    Posts:
    11
    The last patch that had functional 2D triggers for me was 5.2.2p4.

    Now, OnTriggerEnter2D seems to be called later than it used to, and I need to at least double my physics time step to get performance similar to before the update. Whether a rigidbody is attached or not, and regardless of whether it's kinematic on one or both colliding objects, the triggers are still firing much later than before. Occasionally, OnTriggerEnter2D is missed entirely. This has been happening since the first 5.2.3 release.

    Please help Unity team, it'd be fantastic to be able to use 5.3.
     
    Last edited: Dec 9, 2015
  8. raglet

    raglet

    Joined:
    Nov 22, 2015
    Posts:
    30
    Same issue here. I actually had no issues with OnTriggerEnter2D in 5.2.3 but it's completely broken in 5.3.0.
     
  9. tedthebug

    tedthebug

    Joined:
    May 6, 2015
    Posts:
    2,569
    Same here, I thought I was going nuts. I've tried kinematic rigid bodies on everything, triggers & oncollision2d & nothing is working.
     
  10. MartinIsla

    MartinIsla

    Joined:
    Sep 18, 2013
    Posts:
    64
    The kinematic rigidbody thing is actually pretty funny.
    If you check it as non-kinematic and play, trigger won't work, but if you check it as kinematic while on trigger, it works.
    It happens vice versa too.
    I think all we can do is cry until Unity fixes this. Or give Godot a try!
     
  11. tedthebug

    tedthebug

    Joined:
    May 6, 2015
    Posts:
    2,569
    Did you log a bug report from within your project?
     
  12. MartinIsla

    MartinIsla

    Joined:
    Sep 18, 2013
    Posts:
    64
    I did, but I did it wrong (sorry, first time I ever report a bug). Now I did it again properly.
     
  13. tedthebug

    tedthebug

    Joined:
    May 6, 2015
    Posts:
    2,569
  14. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    1,920
    The only known issue is that there can be a single physics-update delay when re-positioning bodies via the Transform rather than using Rigidbody2D.MovePosition (as is recommended). This has been fixed and is on its way to the patch release stream for 5.2 & 5.3.

    Can you please provide me with bug case numbers please?
     
    theANMATOR2b likes this.
  15. MartinIsla

    MartinIsla

    Joined:
    Sep 18, 2013
    Posts:
    64
    Case number is 752059
     
    RastaKillah likes this.
  16. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    1,920
    Thanks!
     
  17. Sitalk

    Sitalk

    Joined:
    Nov 12, 2013
    Posts:
    26
    In my case, with Unity 5.3, when a character is falling on some object (say a spike) OnTriggerEnter2D will not fire until the character is landed and his velocity.y is zero ~90% of the time.

    On 5.3 this, inside a OnTriggerEnter2D, will return zero most of the time:
    Debug.Log( MyMainCharacter.GetComponent<Rigidbody2D>().velocity.y )

    On 5.2 I had always the correct (negative when falling) velocity values.

    And this is only an example, most of the OnTriggerEnter2D events now are delayed (or failing) for me too.
     
  18. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    1,920
    So I've just looked at case 752059 and it's simply that you're moving a static collider (something you should never do). Static colliders don't actually detect contacts themselves, only dynamic/kinematic do. This is why moving a dynamic collider contacts things whereas moving a static collider doesn't.

    To make matters worse, the Rigidbody2D that your dynamic collider is attached to is sleeping so it never detects a collision nor does it have any reason to wake up. If you set the Rigidbody2D to 'Never Sleep' then it detects the static collider overlapping it.

    If you set the dynamic body to not sleep then moving the static collider over the dynamic one causes a collision to be detected but that's the (awake) dynamic one detecting that.This is stock Box2D.

    I am following your reproduction steps of:
    Triggers only working if Rigidbody is active.

    This has been a kind of 'undefined' behaviour so I'm investigating what changed.
     
    Last edited: Dec 9, 2015
  19. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    1,920
    Bug reports are the only way to get these things resolved. Please create a simple reproduction project and submit a bug report.

    Thanks.
     
  20. MartinIsla

    MartinIsla

    Joined:
    Sep 18, 2013
    Posts:
    64
    I admit I'm pretty new to Unity, but it worked perfectly before Unity 5.3. My game was almost ready to be released.
     
  21. DiegoAtaqueEnLongBeach

    DiegoAtaqueEnLongBeach

    Joined:
    Feb 9, 2015
    Posts:
    5
    I am not trying to be mean... But, there is something called version locking... Which means you stick with one version of the engine you are using, if you are going third party for that.

    It will help you avoid issues like that, as unexpected bugs may arise with updates.
     
    theANMATOR2b likes this.
  22. Grafos

    Grafos

    Joined:
    Aug 30, 2011
    Posts:
    218
    My almost ready for release game (apart from a random performance spike I had been investigating) is also broken on android after updating to 5.3.

    Issues so far
    -------------------------------------------------------------------------------
    2d collider triggers randomly do not register (static or not).

    My touch controls do not register the OnPointerExit event.

    The bug in which adb.exe does not terminate and I have to kill it manually through taskbar before every build has returned

    Lastly, when I perform a Build and Run I have to manually start the game on the mobile device after building (instead of it launching automatically), though that has been going on for a while.
     
  23. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    1,920
    None of which helps resolve any problems you might have. Have you done any bug reports?
     
    theANMATOR2b likes this.
  24. Grafos

    Grafos

    Joined:
    Aug 30, 2011
    Posts:
    218
  25. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    1,920
    Working with another user who has kindly provided a bug case I think I've isolated the change in behaviour. If you're moving a static collider trigger (a collider not attached to a Rigidbody2D with IsTrigger checked) then you'll no longer receive callbacks for it.

    In Box2D, you don't receive callbacks for sensors (triggers) until the next physics update (they are always delayed a single update). Previously we explicitly iterated all trigger contacts and performed a callback for each to ensure we do report callbacks immediately unlike stock Box2D. However, during a 5.2.3 patch, this changed slightly and this very specific behaviour was modified.

    I am making a modification now that will revert this behaviour and add a test to ensure it never gets reverted in the future but again, this is related to static colliders only. You should not be moving them but it seems lots of people do even though it's expensive to do so. You should always add a Kinematic Rigidbody2D, again, something that is perceived as expensive from what I can tell.

    I am supposed to be on leave this week but I'll get this into the release stream regardless as it seems to be affecting more than a few users.
     
    majman likes this.
  26. aj-highline

    aj-highline

    Joined:
    Feb 22, 2014
    Posts:
    12
    I just submitted a similar bug, which might possibly be related - 752215. Collisions are no longer triggered when colliders are being directly animated via Mecanim. This used to work fine. Ridigbodies are attached, so it is not exactly the same problem, but perhaps it is adjacent!
     
  27. AttilioC

    AttilioC

    Joined:
    Jun 29, 2014
    Posts:
    84
    Hello,

    I've got the same issue, strangely enough only happened with the game boss, normal enemies were unaffected.

    My boss has a Rigidbody2D and a trigger box collider 2D, and detect collisions with player bullets through Trigger Enter 2D. Player bullets have a 2D box collider set to trigger.

    In my case setting the boss rb2D sleeping mode to Never Sleep (as opposed to Start Awake) fixed the bug. I can provide more info if needed.

    Cheers!
     
  28. Bunderant

    Bunderant

    Joined:
    May 29, 2013
    Posts:
    11
    Thanks for looking into this, MelvMay. I'm not sure the change you described will solve the issue for me, but I'm hopeful.

    I should note, I've had late (sometimes missed) trigger contacts regardless of discrete/continuous collisions, rigidbody or not, kinematic or not, always awake or not.

    To be more specific, I have a bullet (Rigidbody2D with a BoxCollider2D set as a trigger) that I am moving by setting its velocity directly. It moves very fast (horizontal velocity over 200), and it collides with polygon colliders on stationary kinematic rigidbodies. This setup worked fine in 5.2.2p4, not so in the first 5.2.3 release.

    Does anyone have a link to an issue representing this bug? I can make a sample project if need be.
     
  29. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    1,920
    Thanks! I've looked at this and I've found what the issue is and will get a fix into the patch release stream ASAP.
     
    majman and aj-highline like this.
  30. aj-highline

    aj-highline

    Joined:
    Feb 22, 2014
    Posts:
    12
    Awesome! Thank you!
     
  31. Manny Calavera

    Manny Calavera

    Joined:
    Oct 19, 2011
    Posts:
    205
    I've pointed out this change in behavior (when moving triggers without a Rigidbody2D) during beta.

    The reason why so many people hit this issue now is because it's not obvious to detect when you have the wrong setup. It used to just work. So a lot of folks were inadvertently going about it this way. Now this recent change in behavior made it very obvious when something is missing.
    But even if you know the theory, sometimes you just forget to add that kinematic rigidbody to the object.

    @MelvMay, does the Editor tells us that we're moving a static collider? Perhaps it would be possible to enable a warning on the console or even in the profiler?
     
  32. georgeq

    georgeq

    Joined:
    Mar 5, 2014
    Posts:
    478
    I my case, yes I was moving indirectly a static collider however adding the kinematic rigidbody does not solve the problem, OnTriggerEnter2D is not always called, I'm having exactly the same behavior with and without the Rigidbody2D.
     
    liuchunyao90 and Bunderant like this.
  33. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    1,920
    I could spend most of the day like I did yesterday on the forums (supposed to be on annual leave btw) replying but it won't help and I won't be able to identify individuals issues without bug reports. Everyone likes to think their problem is the same then they can just wait for a fix. Know that I've only received two bug reports so far and have identified two issues, both of which have been fixed and I'm waiting on the build-farm for the thumbs-up then it can go for review and then into the patch release stream.

    Will this solve your issue? I sincerely hope so but without a bug report I cannot help further.
     
  34. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    1,920
    Sorry to quote you but this is the problem right here. It's easy to convince yourself it's the same problem. I'd sooner have duplicate bug reports than very few. :)

    I have no idea if there's a single bug or many bugs. I'd like to get them all fixed and in your hands before the Xmas break (even though I'm supposed to be on my Xmas break) but I have no way of knowing without bug reports. I'd like to sleep easy knowing they're fixed!
     
    theANMATOR2b likes this.
  35. tedthebug

    tedthebug

    Joined:
    May 6, 2015
    Posts:
    2,569
    I'll send one for mine tomorrow. I have tried so many things I can't remember what state it is in now so will do a couple of scenes with each combination separated.
     
  36. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    1,920
    Awesome, that would be most appreciated! If you can keep any attached project as simple as possible, that would be great.
     
  37. martindrek

    martindrek

    Joined:
    Dec 10, 2015
    Posts:
    6
    I'm having almost the same issue. I've submitted a bug report as well - 752570

    My initial post:
    OnCollisionEnter2D not working during scaling

    I'm having serious issues with Physics 2D in latest Unity (5.3).

    Either my approach is deprecated (as i've had no issues with previous versions < 5.2) or is the 2D Physics broken.

    Situation: Player needs to increase the gameobject's scale and determine if it's colliding with other gameobjects during the process.

    The problem: If gameobject is scaling, Unity does not invoke OnCollisionEnter. Please note that everything works as it should when object is not scaling. Using triggers also causes the same issue. I've tried increasing the colliders radius manually, i've tried increasing the object's scale, different code examples for scaling, even switched to OnCollisionExit, but the result is the same - no collisions when Scale is changed.

    I never had the issue with Unity 5.2.1.

    I've made an example: https://www.dropbox.com/s/jq9m8642r3h9nj5/Example.unitypackage?dl=0
    Reproducing the issue:
    1.) Play _01.scene
    2.) Click and hold. (Please note that following the gameobject with mouse ise not necessary)
    3.) If object is scaled, no collisions are detected by Unity.

    Edit: I'm using Windows 10 64bit, not Windows 8 as stated in the bugreport.
     
    Last edited: Dec 10, 2015
  38. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    1,920
    Thanks, I'll take a look at your case. Have you tried 5.2.3 patch? 5.3 is pretty much identical to that. Any fixes or changes applied to 5.3 have been applied to 5.2 via the patch system.
     
  39. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    1,920
    I'm using your project in 5.3.0f4 and the balls bounce off each other. I have to click and hold on a ball to make it scale but it continues to hit the walls and the other ball.

    The only thing I can think of is that you've modified the global physics settings somehow because the reproduction project you gave was a package which wouldn't contain those.
     
  40. martindrek

    martindrek

    Joined:
    Dec 10, 2015
    Posts:
    6
    Hi MelvMay

    When the ball is scaling, is the log window printing out text? For me, it isn't.

    Being more precise - if the ball is increasing, the size gets altered correctly and there's no issues with the bounce itself. The problem for me is that Unity does not call OnCollisionEnter2D when balls bounce together (OnCollisionEnter is not called by Unity (no log output) when the ball is increasing. If it's not increasing, OCE-method is called). I will try to make a video to describe the problem.

    Link to project: https://www.dropbox.com/s/bzfqv625mon83nt/BouncingBalls.zip?dl=0

    I'm starting to think it might do something with Windows 10 and its Framework what the Unity is using.

    I'm testing the same project on Windows 7 and will post the results.
     
  41. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    1,920
    Hold that. For some reason the original package didn't reproduce for me. The case has been through QA and their attached project does duplicate the issue. Thanks!
     
  42. fishg

    fishg

    Joined:
    Jul 25, 2014
    Posts:
    90
    I have the same problem too.I was change Edit->ProjectSetting->Physics 2D -> Time to Sleep , from 0.5 to 100,
    looks like temporary fixed.
     
  43. Grafos

    Grafos

    Joined:
    Aug 30, 2011
    Posts:
    218
    Hi Melv, thank you for your efforts and time. Sometimes I post on the forums with issues to see if it's something simple that I might be able to fix with advice by the community without bothering UT. Other times I want to check if it's a common issue or something system specific.

    Of all the issues I mentioned in an earlier post, there's only two left with only one really affecting my game (the trigger issue). I can verify that it is indeed related to scaling as martindrek reported. I have some problematic triggers with a squash and stretch script attached, as soon as I deactivated the said script, triggers started working fine on those objects.

    I am usually reluctant to post a bug report, fearing I might waste your time with a non-issue or something you already know. I also never assumed duplicate bug reports would not bother you, I always thought they would be a nuisance. I'll keep everything you said in mind if I run to any new issues in the future.

    Also, thank you for the explanations regarding non-static objects and rigidbody requirements, I never knew this, it might help with some performance issues I have been trying to figure out.
     
    theANMATOR2b likes this.
  44. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    1,920
    Thanks! You're never wasting time posting bugs. Even if the bug has already been reported, it's marked as a duplicate and I always try to test against all the duplicates to ensure it's the same thing. If anything, I don't get enough bug reports!

    Thanks for your feedback.
     
    theANMATOR2b likes this.
  45. martindrek

    martindrek

    Joined:
    Dec 10, 2015
    Posts:
    6
    MelvMay, I sincerely appreciate all the help you've been provided. I never would have guessed one could find official forums so useful as normally the real help you get is from other users.

    I tried to revert back to 5.2.1f1 (Until the problem is fixed, give 5.2.1f1 a try as i don't recall any problems with colliders/triggers on 5.2.1f1) but the installation seems to be broken. It fails at 76% by saying Internet Connection Lost. I've tried different connections and different PCs and the problem is still there. It seems like files are missing from the server.
     
  46. liam1135

    liam1135

    Joined:
    Mar 10, 2014
    Posts:
    1
    I fixed this issue in two 5.3 projects by setting the sleep mode of involved rigidBody2D's to neverSleep from startAwake.
     
  47. AGSMarcinDraszczuk

    AGSMarcinDraszczuk

    Joined:
    Mar 31, 2015
    Posts:
    21
    I've encountered the same issue - OnTriggerEnter2D is not called when resizing a collider the same frame a collision would occur. Just submitted the case 752703:

    OnTriggerEnter2D is not called in Unity 5.3.0f4 when resizing collider

    1. What happened
    OnTriggerEnter2D is not called if the collider is resized the same frame as collision occurs. This bug wasn't present in previous version 5.2.3f1.

    2. How we can reproduce it using the example you attached
    Open Scene.scene and run the game. The small sprite should turn red upon colliding with the large sprite, but it doesn't - OnTriggerEnter2D is not called. Removing the instruction that randomly resizes the collider from Script.cs causes collision to be detected correctly.
     
  48. InfinityCoder88

    InfinityCoder88

    Joined:
    Oct 4, 2013
    Posts:
    241
    Hi friends,
    I had the same issue, I managed to fix this by adding an Rigidbody2D on my object and setting the Is Kinematic to true, and suddenly all the issues are gone, in my case the object follows the player , under the camera I'm using'it to triggering the "killing" the player . Hope this will help somebody !

    Cheers,
     
    theANMATOR2b likes this.
  49. Volcanic-Penguin

    Volcanic-Penguin

    Joined:
    Feb 7, 2013
    Posts:
    9
    Added RigidBody2D's with isKinematic true which solved the problem for all objects except one.

    Had to make sure Animator components have Apply Root Motion set to false for my own rotation to take effect. (seems to apply to both animation and code rotation)

    The one object that's still not working properly is an object that is scaling in and out in it's animation. If I remove the scaling animation the collision triggers correctly. So I'm having the same problem as martindrek and AGSMarcinDraszczuk.
     
    Last edited: Dec 10, 2015
    theANMATOR2b and InfinityCoder88 like this.
  50. Cuicui_Studios

    Cuicui_Studios

    Joined:
    May 3, 2014
    Posts:
    31
    Same here case 752764

    Everything was fine on previous versions. The scenes I have problems now with were finished few months ago, and yesterday I upgraded to 5.3 because I need the new JSON functions and this scenes are now unplayable because of the bugs on Colliders.

    And MelvMay, do not take it as personal. But is the duty of the Technical support fixing our issues, if you had to be on your holidays it´s fine, tell your boss to put other guys working on this until you came back, or even better, tell the guy who is in charge of the updates that he has to give us tested versions.

    Since Unity 5.x it feels like Unity throw us versions and versions and versions that they didn´t tried before. Is the job of the users to find bugs on basic stuff and even worst, on new stuff. I still remember the release of Unity 5 with those amazing audio tools that doesn´t worked on iOS.

    When Unity give us upgrades with those big errors we spent a lot of time looking for mistakes on our codes. This wasted time is extra cost for our projects.
    So I really thank you to do not refer to the Unity team vacations while we are paying a lot of money for a software to get our work easy, faster and better and Unity does not comply with the contract.
     
    CoolCasualCat likes this.
Thread Status:
Not open for further replies.