I’m working on a driving game, where cars are spawned all around a city. The cars used to be using box colliders, and everything worked great. But I switched them all to use mesh colliders instead, and now every time one of these cars spawns (whether at scene-load or later), the game briefly (but very noticeably) halts. I assume it’s doing some sort of physics calculation.
The cars are not marked as Static, and they all have a Rigidbody on the parent (the mesh colliders are generally on grandchildren, I don’t think that matters). Non-Kinematic. Does anybody have any tips?
I’d try spawning a lot of cars at once while watching the profiler. This should give you a good clue of which part of the spawning process is halting the game.
Can you try ensuring that all the vehicle’s colliders have scale 1?
Note that you may configure a scale at the import settings in Unity for each 3D file. If the issue is the scale, then it would be fixed by ensuring all colliders have 1:1 scale and applying the scale in the importer:
I finally was able to get around to this, at least setting making sure the local scale was 1,1,1 on the mesh with the collider - it didn’t really help, though to be fair the car is still scaled, just at a higher level. What sucks is this project is kind-of a mess - each car has different scale values, some cars even have some of their parts scaled differently.
This effect is pretty darn bad, if I spawn 50 cars (which I do at the start) the entire playback pauses for 13 seconds as those cars do “Mesh.Bake Scaled Mesh PhysX CollisionData”
Does anybody have any idea how I can stop this from noticeably halting Unity for over 10 seconds in the initial spawn? I’m currently spawning 50 vehicles, and in the future that number could go up. There has to be something I can do, some way to stop Unity from doing this baking. Or maybe do the calculation once beforehand? I think PhysX can do that…
BTW, I did check the “Prebake Collision Meshes” box.