Search Unity

Question Why position impacts performance?

Discussion in 'Physics' started by georgeq, Jun 18, 2022.

  1. georgeq

    georgeq

    Joined:
    Mar 5, 2014
    Posts:
    662
    I'm having this strange issue:

    I have a situation in which a set of 25 game objects has to be moved (teleported)... Game objects are disabled at first, then they are moved and enabled, one by one, each of them is disabled by the gameplay process, when all become disabled they are moved to another location and then re-enabled again. I don't have any performance issues when this process occurs at floor level Y=0, but when Y=-2,700 the moving process takes more than 1 second, which is unacceptable. The same code is used in all cases, so the problem seems to be on the physics engine. These game objects are just static colliders that serve as floor, they don't have rigid bodies.

    profiler.png
     
  2. arkano22

    arkano22

    Joined:
    Sep 20, 2012
    Posts:
    1,924
    This happens inside Physics.Contacts, so my *guess* is that you're using continuous collision detection for these objects. When teleporting them far away from the origin, they are calculating contacts against everything on their path from point A to point B. The longer the path, the longer this process takes. Does this make sense?

    Could you share the code you're using to enable/disable/move the objects around?
     
    Last edited: Jun 20, 2022
    georgeq likes this.
  3. Vincent454

    Vincent454

    Joined:
    Oct 26, 2014
    Posts:
    167
    Are the objects maybe marked as static? If so, they shouldn't be moved anymore maybe thats the reason
     
    georgeq likes this.
  4. georgeq

    georgeq

    Joined:
    Mar 5, 2014
    Posts:
    662
    Thanks... I think found the problem, I'm using a mesh collider and the number of vertices changes with distance, not 100% sure yet, but it seems the mesh rebuild process is forcing the physics engine to recalculate the whole world.
     
    Vincent454 likes this.
  5. Vincent454

    Vincent454

    Joined:
    Oct 26, 2014
    Posts:
    167
    Wow thats interesting thanks for the update