Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Issue with Physicc2D performance on 2022.1

Discussion in '2D' started by Dasp, Jul 4, 2022.

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

    Dasp

    Joined:
    Sep 25, 2012
    Posts:
    38
    Hi, we encountered issue with performance after upgrading from 2021.3 to 2022.1. Here is screenshot of physics2D performance on android debug build. On 2021.3 we had 16.6ms per frame for everything. Now we have 22ms only in physics2dFixedUpdate. No major changes happened to physics or anything in the scene. We are not using rigidbodies, only colliders.

    Screenshot_1.png

    After some testing I noticed that changing all polygon colliders 2d to box collider 2d improves performance significantly. Any help how to solve the issue? We would like to get back that performance we lost after update.
     
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,512
    A BoxCollider2D creates a single physics shape, a PolygonCollider2D can create lots even hundreds so it's not surprising.

    I suspect you're not moving anything then because these are Static and should never be moved. If you are moving them then it's the absolute worst thing you can do. You should learn how to use the physics system correctly here which is that Rigidbody2D move, Colliders are just along for the ride. Modifying a Transform is doing 2D physics wrong and doing this cause the colliders to be recreated completely.

    Are you running the physics per-frame because you state per-frame time and physics normally runs during the fixed-update. Also, stating the total time taken for the "frame" isn't useful in this context if you're making the statement that physics is causing this. What is the proof i.e. what specific part of the simulation step is taking longer? Presumably you know this because you're stating it's 2D physics that's taking the extra time. Is it finding contacts, resolving contacts, something else?

    Also note, the profiler frame you show is the fixed-update running twice because Unity decided that game-time was lagging. This calls everything in fixed-update twice; scripts, animation, physics, everything so it's showing double the time.
     
  3. Dasp

    Dasp

    Joined:
    Sep 25, 2012
    Posts:
    38
    as I stated before on Unity 2021.3 there was no issue with performance for 2d physics. Our game runs under 10ms per frame so it is easily noticeable. We are using collider mostly for physics raycasting. So even if the issue is with our approach why sudden drop in performance between Unity versions?

    Let's assume that the physics engine is really finding contacts and resolving contacts. How we can find those contact when on our colliders we don't see any? How engine finds those contacts? Our collision matrix is turned off.

    What the recommendation here?
     
  4. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,512
    You've still not stated what is taking more time, simply that you are sure it's 2D physics.

    I don't have the project, you do so you have all the info. Asking me questions as if I can somehow tell you what is going wrong isn't realistic. You need to provide some information for me to comment on.

    So again, what is taking more time specifically?
     
  5. Dasp

    Dasp

    Joined:
    Sep 25, 2012
    Posts:
    38
    If you tried to understand first post you would understand that the screenshot shows what is taking more time. What information do you need more?
     
  6. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,512
    Answered separately. First, as I've said, if you're modifing a Transform then you're doing it wrong. That's what all those unnecessary SyncTransforms are. Add a Rigidbody2D and change its position/rotation. The colliders won't need to be recreate then and no sync-transforms will happen either. If you're explicitly controlling it then use a Kinematic Body-type because this is exactly what it is for. If you want contacts between Kinematic/Kinematic or Kinematic/Static calculated then use Rigidbody2D.useFullKinematicContacts and then ask for the contacts using the GetContacts call. That said, this answers your question as to how to get contacts but I have no idea what you're doing so no idea if this is appropriate. Using a Rigidbody2D if you ever intend to move is exactly what you should be doing though.
     
  7. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,512
    You're being critical of me when you're simply not following that showing me the total current time taken gives me no information whatsoever as to what part under it was taking less time before.

    So in short, my answer is that I don't know how to help you unless you can tell me what part under the simulation is taking more time as I've asked above.
     
  8. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,512
    I've just seen that you've now reported my reply as being "passive aggressive"! I am trying to get you to understand that what you're providing doesn't give me any information to help you.

    If you don't believe I'm trying to get more information to help you then I think it's best for me to leave this conversation here which is a shame.
     
  9. Dasp

    Dasp

    Joined:
    Sep 25, 2012
    Posts:
    38
    So I will try to type it clearer. We don't use physics2D for anything, we use only colliders with physics raycasting.
    I understand we might need to add rigidbody and I don't look at SyncTransform as much because it takes only 0.45ms.

    What I'm interested is why for example FindNewContactsTask takes so much time? Again we use only colliders and their purpose is to work together with physics raycasting when user interacts with the game.

    We sometimes move objects using transform (they have colliders) but performance issue persist even when nothing moves.

    Is there a way to turn off contact check in the physics2d?
     
  10. Dasp

    Dasp

    Joined:
    Sep 25, 2012
    Posts:
    38
    Then just write what you need to know from me? I can gladly provide it. I'm asking here because there is not much information about certain parts of physics2d engine and apparently Unity employees are also not eager to share
     
  11. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,512
    It is now my evening, I am spending my personal time trying to help you and you are doing nothing but being critical of both myself and Unity Employees.

    I do not know why you are being so aggressive. I have only asked you for more information above.

    I have above when I asked what part of the physics update is taking more time than before. Each item under it is a specific part of the engine. As I've said a few times now, knowing what the total time is now and not what it was before doesn't give me any clue as to what is taking more time.
     
  12. Dasp

    Dasp

    Joined:
    Sep 25, 2012
    Posts:
    38
    Hey man, it's not my job to know if you are using your personal time or not. If you have Unity Technologies profile I expect professionalism and I'm still waiting for any response about what would you require from me to better understand the issue? I try to be respectful but I don't have patience for that.
     
  13. Dasp

    Dasp

    Joined:
    Sep 25, 2012
    Posts:
    38
    Never mind we will resolve the issue ourselves. Admin can close this thread.
     
Thread Status:
Not open for further replies.