Search Issue Tracker

Postponed means that the issue was either a feature request or something that requires major refactoring on our side. Since that makes the issue not actionable in the close future we choose to close it as Postponed and add it on our internal roadmaps and technical debt pages instead.

Postponed

Votes

3

Found in

4.3.0f4

Issue ID

580741

Regression

No

Performance issue when using PolygonCollider2d.SetPath().

Physics2D

-

1) What happened
Performance issue when using PolygonCollider2d.SetPath(). This example shows the timing difference when using MeshCollider's sharedMesh vs Polygon2D's SetPath. It takes about .3 seconds to get the component of an object and copy the mesh over, but it takes about 1.9 seconds to get the component of an object and set the path. These numbers are for 1300 vertex objects and the Console window will show times for smaller amounts of verticies.

The performance difference seems to lie somewhere in PolygonCollider2D.SetPath as the functions are not calling anything else differently. To see this open the SpawnTest.cs file and the PhysicsWrapper.cs file. The SpawnTest's RunBlobSpawnTest() function between the first stopwatch, calls PhysicsWrapper's CreatePoly function. If you look at PhysicsWrapper.CreatePoly you will notice the difference. This performance issue may not be able to be fixed, but it is worth pointing out.

2) How can we reproduce it using the example you attached
To reproduce the issue, which I already have done, open the project and open the SpawnTests Scene press play and until the console window logs "Done." This will take about 5-10 minutes and will seem like iit is hanging, but is trying to execute the Code. Once the program has finished running view the console window for timing information.

Note that I have not had it crash and the function works properly, it just takes a long amount of time with high amounts of verticies.

Comments (4)

  1. iileychen

    Apr 26, 2017 16:13

    It seems cause hanging for my case, the amounts of verticies is around 300, not very large. Anyone encounter this?

  2. Mikael-H

    Feb 08, 2016 14:06

    @Scabnog Do you mean just reverse the index of the paths when setting them? I tried that and didn't really see any improvement.

    This issue is making it impossible for me to work with 2D physics in a procedural voxel world. Can't unity just make some type of 2D mesh collider instead that doesn't do a lot of fancy stuff?

  3. Leuthil

    Aug 21, 2015 20:59

    I too noticed that the SetPath stuff is very slow and it's the main issue behind my game being slow at the moment... At this point I'm stuck until this is fixed (if it can be fixed?).

  4. scabnog

    May 14, 2014 20:10

    I just want to confirm that I had the same issue for PolygonCollider2D.SetPath() with a large number of paths & vertices. Try setting that paths in reverse order. Once I tried this, I no longer had a significant issue. I'm not sure why, but it appears that the function slows down as the path index increases if there are already paths/vertices assigned to the polygon. Perhaps some internal validation or copying?

Add comment

Log in to post comment

All about bugs

View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.