Search Unity

Bug Physics2D broken on iOS specifically

Discussion in 'Physics' started by matthew_cactusstudios, May 29, 2023.

  1. matthew_cactusstudios

    matthew_cactusstudios

    Joined:
    Aug 19, 2020
    Posts:
    5
    Hey,

    We have recently updated our project from Unity 2021.1.28 to Unity 2022.2.20 and encountered a bug with physics2D. The physics on iOS behaves unexpectedly, in some cases objects with colliders and rigidbodies fall through other colliders and in other instances bouncing with weird impulses. This is specifically happening on iOS devices, the physics work fine in both editor and android. We have done some investigation and created a fresh project and been able to reproduce it again by building it for iOS. We simply have a square sprite with a rigidbody and boxcollider2d and a ground box with a collider. We have also noticed that when an object is pointed it behaves as expected. I have attached a video from an iOS device and the repro project. Has anyone else encountered this or have any suggestions on how to fix it?

    Thanks!

    Project:
    https://drive.google.com/file/d/1yFuj1GK82-qOCLlRXS289S071Ld8Grf_/view
    Video:
    https://drive.google.com/file/d/1gIHuE2z6wcKs6XKSW6DLMtUyKxMLh0qG/view
     

    Attached Files:

    paljan and ramsayamarin like this.
  2. ramsayamarin

    ramsayamarin

    Joined:
    Feb 10, 2013
    Posts:
    21
    I found the same exact problem happen only on ios device after I upgraded to the latest unity version, things are bouncing around randomly. someone suggested downgrading to 2021.3
     
  3. matthew_cactusstudios

    matthew_cactusstudios

    Joined:
    Aug 19, 2020
    Posts:
    5
    Im now using packages in my project only available in 20222 so downgrading would break a lot of other stuff. Hoping someone from unity can respond to us.
     
  4. paljan

    paljan

    Joined:
    Feb 9, 2015
    Posts:
    32
  5. matthew_cactusstudios

    matthew_cactusstudios

    Joined:
    Aug 19, 2020
    Posts:
    5
    Hey @paljan, thanks! Cant believe this isnt a more common issue, no one must make 2d games for iOS.
     
  6. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,497
    This is the first I've heard of this! Looks like the report has a lot of back/forth between customer and QA but has landed in 3D physics (which is obviously wrong) so I wasn't notified so I'll get that moved.

    So this is very strange for a few reasons but mostly because there is no platform specific code in 2D physics so only doing that on iOS is bizarre. Also, the core of 2D physics (Box2D) hasn't changed for those versions so I'm not even sure what the regression could be here.

    I cannot build on iOS here at the moment so I'll need to organise with our 2D QA to reproduce this however, a quick look at the project shows that all of these Rigidbody2D are using extrapolation so maybe it's related to that somehow? Maybe you could turn that off and/or use interpolation rather than extrapolation. The reason I'm guessing about this feature is because it's rarely used outside of a prediction set-up i.e. a networked client for instance so this could possibly account for why it's not been reported elsewhere.

    I know you mention random impulses but it's not clear what you mean by that. In the video above I see it suddenly overlapping and trying to resolve the overlap so maybe you mean that the impulses here are "random" i.e. it's desperately trying to resolve the overlap. If not, could you elaborate on what you mean here? It might narrow down the issue somewhat.

    Anyway, I'll get this case assigned to the 2D team where it belongs and see if I can reproduce the issue and track it down.
     
  7. paljan

    paljan

    Joined:
    Feb 9, 2015
    Posts:
    32
    First, sorry for kinda hijacking and mixing this up, as MelvMay seems to be responding to both of us now. I just wanted to add, that in the project we supplied to QA for the issue in the tracker that I was referring to, we are not using extrapolation, so it seems that is not the issue.

    I can't understand how QA could have flagged it under 3D physics, but the back and forth we had was only due to services preventing the QA engineer from testing and verifying the project.

    I'm just happy you've now recieved our report also and things are moving forward, as this is preventing us from releasing with newer version until the physics bug is fixed. It's still active in the 2022.3 LTS version.

    @MelvMay Feel free to contact me with for example a direct message if you wish to discuss the already reported issue (UUM-27603) once you get it set up and tested!
     
    MelvMay likes this.
  8. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,497
    Although there's no desperate need to test this but I'm curious if the same happens in 2022.1.24 on your side or only in 2022.2 onwards.

    EDIT: Just after I typed this, I had it verified by QA that it doesn't happen in 2022.1.24f1

    I'm getting set-up to reproduce this today.
     
    paljan likes this.
  9. any_user

    any_user

    Joined:
    Oct 19, 2008
    Posts:
    374
    Not sure if it's the same issue, but I'm also experiencing strange behaviour of 2D physics on iOS builds specifically. In my case, kinematic objects randomly start to move after collisions with certain objects (seemingly random) – which is not happening in the editor and in Mac builds. It happens in 2022.2.17 and looks the same after upgrading to 2022.3.0.
     
    CrystalDynamo likes this.
  10. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,497
    Certainly sounds different. Very odd though, the physics engine doesn't touch Kinematic bodies upon contact. I would suggest creating a separate bug report on that if you can please; only way to be sure. If you would post the case number too, that would be good.
     
  11. matthew_cactusstudios

    matthew_cactusstudios

    Joined:
    Aug 19, 2020
    Posts:
    5
    MelvMay likes this.
  12. any_user

    any_user

    Joined:
    Oct 19, 2008
    Posts:
    374
    I was able to narrow it down, it's reported with a small repro as IN-43433. It happens when a capsule collides with a box using the flat part of the capsule. It also seems to have an impact what the value of velocity iterations is, if it's set to an odd value (e.g. 9 or 11 instead of 8), the kinematic object moves much faster after collisions. Anyway it shouldn't move at all, so it might be just a side effect of some other problem.
     
    MelvMay likes this.
  13. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,497
    That's certainly not an isolation of the problem above which can be reproduced with only polygons. This is proving to be a real devil of a bug to find TBH. Not that debugging such things is easy in the first place but with XCode deploying to an iPad certainly has its debugging challenges.

    Anyway, I'm working on it. I'll update with any fix I find.

    Thanks for the info.
     
  14. CrystalDynamo

    CrystalDynamo

    Joined:
    May 22, 2014
    Posts:
    120
    Yeah I just came from Unity 2021 and 2022.3.1f1 on iOS I have things bouncing everywhere in 2D after collision. The unity simulator works fine. Under 2021 it worked fine also. I can't go back to 2021 because I migrated and discovered my backup was not done first. So I hope this gets fixed.
     
  15. CrystalDynamo

    CrystalDynamo

    Joined:
    May 22, 2014
    Posts:
    120

    Yep thats my exact problem. My bigger problem is I can't downgrade my app and never had a backup first. I know stupid right. So I hope it can be fixed moving forward.
     
  16. CrystalDynamo

    CrystalDynamo

    Joined:
    May 22, 2014
    Posts:
    120
    WOW its still not working after installing 2022.3.2f1. This is starting to be areal problem.
     
  17. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,497
    Good news.

    I have found and fixed the issue reported above and have tested it on the several reported projects and all are the same issue. Unfortunately there is no workaround for this and it even affects the multi-threaded solver too.

    I'll now prepare the fix PRs for all Unity versions for 2022 onwards. I cannot give you a time when it'll land in a public release because the PRs need build-farm validation, review, QA and to land in the appropriate release branches.

    However, I will report here as each one lands in the release branches so will be in the subsequent release.
     
    any_user, MousePods and CrystalDynamo like this.
  18. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,497
    Of course, the bug was only just seen as I described above. There's no way it can be in a public release yet.
     
    CrystalDynamo likes this.
  19. CrystalDynamo

    CrystalDynamo

    Joined:
    May 22, 2014
    Posts:
    120
    Awesome , thanks mate. Legend :)
     
  20. CrystalDynamo

    CrystalDynamo

    Joined:
    May 22, 2014
    Posts:
    120
    SNAP, sorry mate I thought the release came out with a possible fix in it, I got too excited when I saw it and never read what was in the release. I can't believe I dropped by and posted that and literally your post was there in less than a minute. Talk about timing. You sir are however a legend for locating and fixing the issue. :)

    PS. Apologies , I know what its like when people are eager for solutions. I am a Senior Software Engineer as well. I get that all the time. I don't want to be that guy. Cheers
     
    MelvMay likes this.
  21. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,497
    I actually fixed it at 5am this morning (couldn't sleep) but waited until now to say because I wanted to get it properly tested on all available projects when I was more awake!

    Yeah, bizarre coincidence our posts crossing at the same time! :)
     
    Unifikation and CrystalDynamo like this.
  22. paljan

    paljan

    Joined:
    Feb 9, 2015
    Posts:
    32
    Thank you @MelvMay for solving this! Considering the report found it's way to you less than ten days ago, I'd say kudos to you and boo to the QA engineer tagging it wrong initially. :D
     
    CrystalDynamo likes this.
  23. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,497
    I have to say that it took me far too long to find the bug simply because debugging C++ on XCode on an iPad was so very painful. If it were Windows, it'd be done in a day or so.

    It happens, especially given the sheer volume of bug reports those heros have to deal with every day. Mostly everything lands in the correct bucket!

    I'll post back here as I get a notification of things landing prior to a release. It'll land under this report ID: https://issuetracker.unity3d.com/is...es-gets-random-impulses-when-using-2d-physics
     
    paljan likes this.
  24. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,497
    So the QA testing is progressing but in the meantime, if you are willing, I've produced a custom-build of Unity for 2022.3.x which you can use to test until the fixes land.

    I'd ask those who are affected by this (above) to DM me and I'll provide a link where you can download it.

    Important Notes: Whilst this download is versioned as 2022.3.4f1, it's not that official version so you should install and use this away from any same version of Unity (it'll conflict) and the resultant builds should NOT be used for production. You should also ensure you have a backup prior to loading your project with this custom-build that you can dispose of afterwards. Any conversion made will unlikely be compatible with any official builds you download. Also, because this build is direct from the 2022.3 repo via our build-farm, it has had no QA and so other features may have broken etc. I cannot offer support on any of those things contained within it. This download is limited to seeing if the reported bug has been fixed in your case on your device(s) and for future readers, this download will be gone when the bug fix lands so any future readers having any problem on iOS, this isn't applicable to you.
     
    any_user likes this.
  25. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,497
    A backport has landed and will be in 2022.3.5f1
     
  26. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,497
    A fix has landed and will be in 2023.2.0a22
     
  27. DiogoQueiroz

    DiogoQueiroz

    Joined:
    Feb 19, 2019
    Posts:
    9
    @MelvMay is there a difference between the backport from 2022.3.5f1 and the fix that will land in 2023?
     
  28. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,497
    It's the same change. We land in the latest (2023.2.x) and process backports of the changeset to earlier branches.

    The changeset landed in 2023.2.0a22 and the identical changeset is backported and landed to 2022.3.5f1 and is in the queue to land in 2023.1.x.
     
  29. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,497
    Unifikation likes this.
  30. DodSHMason

    DodSHMason

    Joined:
    Feb 19, 2019
    Posts:
    18
    Oh what a timing, Just started working on porting my android game into iOS... and this!

    gameobject with 2d physics are falling through floor, flying all over. going crazy....

    why... why...
     
  31. DodSHMason

    DodSHMason

    Joined:
    Feb 19, 2019
    Posts:
    18
    Currently using 2023.1.1f1 ... will 2023.1.2f1 fix this issue? where is 1.3f1 I can't find it in hub q_q ....
     
  32. DodSHMason

    DodSHMason

    Joined:
    Feb 19, 2019
    Posts:
    18
    + It's fine on 2021.3.15f1 ... just Latest versions having issues i guess... sigh
     
  33. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,497
    Because of a bug that's fixed as described above. ;)

    Of course not, we can't fix a version that's been released. It'll be in the next version which I specified.

    Because it's not released yet. I stated above it'll be in 2023.1.3f1 but not that the version has been released. I was making good on the promise that I'd keep the devs in this thread informed on progress. Please read the thread.

    Yes, it was a memory issue that appeared in the 2022.1 beta as shown in the bug report above: "Reproducible with: 2022.2.0b8+".

    At least one dev from above has tested the custom build I put up and can verify that it fixed their issue.

    Note that you can edit your posts, you don't need to make multiple posts! ;)
     
    DodSHMason and CrystalDynamo like this.
  34. DodSHMason

    DodSHMason

    Joined:
    Feb 19, 2019
    Posts:
    18
    @MelvMay

    Thank you sunny klingon. I will wait <3 KAPLA!

    oh and I noticed something while working on porting, Is it normal iOS version of game consuming much much more RAM compare to Android version?
     
  35. Unifikation

    Unifikation

    Joined:
    Jan 4, 2023
    Posts:
    1,087
    Can you detail what was changed and what any possible side effects of those changes might be, so as to look for them. Building a physics heavy game.

    and, thank you!
     
  36. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,497
    That's not the subject of this thread so please create a new thread. I'm not an expert on iOS so I'm not the person to ask.

    There are no "details" to give without showing the code; it's a simple fix to a regression and not a change in behaviour or anything. You should be good to go.

    Bug count now back at zero for 2D physics. :)
     
    Unifikation likes this.
  37. Unifikation

    Unifikation

    Joined:
    Jan 4, 2023
    Posts:
    1,087
    Thank you, very much, and well done. It often seems like I only use Unity because of your thoroughness with 2D physics, everything else about the engine feels (and is) far less reliable and often no fun at all.
     
    MelvMay likes this.
  38. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,497
    Kind of you to say, thanks! I do admit that I'm pretty passionate about keeping it bug free so I go all in when something comes in. Down side to having a bug count of zero is that when one inevitably comes in (or as above you're made aware of it), it's like a big sore finger and it's pointing at you!

    The one above was strange in that the compiler was giving different results on iOS as compared to Windows so it was particularly difficult to track down. No obvious logic issues and no platform specific code either.
     
  39. Unifikation

    Unifikation

    Joined:
    Jan 4, 2023
    Posts:
    1,087
    Very seriously, this kind of diligence and rigour is a great relief to witness and rely upon. In a world increasingly casual about its ever more blatant disregard for thoroughness and its significance to that which can be built upon it, you are a diamond!

    And I wish Unity would recognise this by focusing more specific endeavour around empowering the creation of highly performant and engaging/innovative games with 2D physics and its inherent advantages for parallax environments that embrace and enhance their play.

    Particualry since "Play Mode" is the ultimate environment for rigging setting iterative experimentation for feel and responsiveness, configuration and relationships.

    I get that 2D and 2.5D aren't glamorous, cutting edge, but Unity is so good at this, and so suited to it, thanks to your rigour with Box2D and extending and enhancing it, that it's a bit of a crying shame that there's not more provision and consideration going on around this category of Unity usage that celebrates and extends this capability to an extreme of its own.
     
    MelvMay likes this.
  40. Thaina

    Thaina

    Joined:
    Jul 13, 2012
    Posts:
    1,167
    And when that would be released ?
     
  41. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,497
    I'm not sure, on the same schedule as all the previous releases I'd suggest. Think they're roughly every 2 weeks which would make it mid/late next week I guess.
     
    CrystalDynamo and Thaina like this.
  42. CrystalDynamo

    CrystalDynamo

    Joined:
    May 22, 2014
    Posts:
    120
    It's out, installing it now. Thanks.
     
  43. CrystalDynamo

    CrystalDynamo

    Joined:
    May 22, 2014
    Posts:
    120
    I think maybe there is another problem now I can't get past my splash screen once deployed. I doubt that's physics related. My app loaded once and when I started game play that just hung as well. No code mods. I'll have to see what error is dumping on the screen when it does happen. It happens all the time but is intermittent. Sometimes just hangs on load. Anyone else having issues ?

    This is 2023.1.3f1.
     
  44. Thaina

    Thaina

    Joined:
    Jul 13, 2012
    Posts:
    1,167
    I need to use 2022.3.5
     
  45. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,497
    Nothing to do with my change which is purely to do with impulses applied in physics. Let's not turn this thread into unrelated issues in that release. :)
     
  46. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,497
    ?
     
  47. Thaina

    Thaina

    Joined:
    Jul 13, 2012
    Posts:
    1,167
    I mean, my project is 2022 stream. And the fix only come at 2022.3.5, so I can't check if it fixed as of now
     
  48. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,497
    No idea if you had the same problem (easy to assume it is by a description) so it's not clear if this will fix your issue; only two bug reports were made. As above I asked for anyone to try that version as a custom build but only a single dev did so but at least it confirmed it solved their problem so fingers crossed for you.
     
  49. CrystalDynamo

    CrystalDynamo

    Joined:
    May 22, 2014
    Posts:
    120
    I have restored a backup and gone back to 2022.3.4f1 and I am waiting until 2022.3.5 comes out. I am just continuing in UNITY environment and simulator for the moment. Hopefully it will deploy to iOS again as just running an app on iOS under 2023.1.3f1 was totally broken for me.
     
  50. DanielForstinger

    DanielForstinger

    Joined:
    Feb 1, 2014
    Posts:
    4
    Any word on when 2022.3.5 will drop?