Physics2D Multithreading not behaving as expected on Unity 2019 or newer

I’m having an issue with physics2d when multithreading is on. I have some floating platforms in my game, they are basically a BoxCollider2D with a Dynamic Rigidbody2D and a script that applies a force on FixedUpdate to perform the intended movement. When multithreading is off it performs as expected, but when I turn it on, it feels like the boxes are 10 times as heavy and the platforms start to wiggle a lot.

Setting useConsistencySorting to true or to false doesn’t help. I’ve also tried tweaking the other values, with no luck.

Steps to reproduce:

  1. Create a new project with the default 2D template on Unity 2019 LTS
  2. Import the test_project.unitypackage attached below
  3. Run the Test scene: it should work as expected
  4. Enable “Use Multithreading” on Project Settings for Physics 2D
  5. Run the Test scene again

Short video showing the issue:

Unity versions that work as excepted: 2018.4.9f1 and 2018.4.25f1
The issue happens on 2019.3.13f1, 2019.4.6f1 and 2020.2.0a19

There’s a similar thread here:

Thanks a lot!

PS: the game has over 150k DAU and it works perfectly with multithreaded physics using Unity 2018 LTS.

6155631–672699–test_project.unitypackage (24.3 KB)

Thanks for the report, I’ll take a look at it on Monday. If you don’t mind, could you create a bug report case with the attached project and send me the case number. It’s not vital but it would allow you to track any fix.

1 Like

Thanks for your quick response. Submitted under id 1267509.

I’ve got the bug case and can duplicate the issue. I’ll investigate the issue soon.

Thanks for reporting this!

So I’ve isolated the issue thanks to your great reproduction project.

It turns out it’s related to the use of the XY constraints in the multi-threaded version of the solver. If you turn off the XY position constraints then the issue will go away which demonstrates this being the source of the problem. It’s related to how contact masses are constrained along the contact normal in relation to the XY constraints.

This is it fixed and now there’s no difference when switching between the two: Screen capture - 6448c46c9f91a18048e0e22979c38632 - Gyazo

1 Like

Awesome MelvMay! Thanks for your quick fix. Now we’ll be able to move to the newer Unity versions :smile:

No problem. I’m assigning the fixes for 2020.2, 2020.1 & 2019.4 to QA shortly.

Here’s the link to track the case: Case 1267509.

1 Like