Search Unity

45 second pause at scene load, from "mesh.bake scaled mesh physx collisiondata" called twice

Discussion in 'Editor & General Support' started by Dreamwriter, Jun 20, 2017.

  1. Dreamwriter

    Dreamwriter

    Joined:
    Jul 22, 2011
    Posts:
    472
    I've got a game spawning a bunch of cars (cloning existing cars in the scene) at scene load, and I just replaced box colliders on each car with mesh colliders that fit the shape of the car better (this is something we need based on what we are doing with this, we can't use box colliders). But now after loading the scene, the game pauses for 45 seconds - 22.5 seconds total when calling GameObject.Instantiate to spawn the cars, and then again when setting their transform.parent.

    These cars aren't static, their mesh colliders are convex, their scales are all 1,1,1 all the way up the parent chain. The cars all have Rigidbodies, but on the root object, not the children with the mesh colliders.

    Any ideas how to fix this issue? Would it be possible to do this "bake" during compile time rather than run time? This is a rather serious problem. After that initial pause everything seems fine.

    Edit: I cut the time in half by setting the parent in the Instantiate call rather than a separate call afterwards, so it only bakes collisions once.
     
    Last edited: Jun 20, 2017
  2. Dreamwriter

    Dreamwriter

    Joined:
    Jul 22, 2011
    Posts:
    472
    Any ideas? This is a really bad issue, I can't show my game off in this state. The scene loads and then everything halts for over 20 seconds as Unity does some sort of "collision baking" before it continues. Can I somehow make it bake the collisions ahead of time?
     
  3. Dreamwriter

    Dreamwriter

    Joined:
    Jul 22, 2011
    Posts:
    472
    OK, this is happening whenever a gameobject with mesh collider is spawned, it pauses the entire game as it does that baking. How can I avoid this? Any help?
     
  4. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    2,510