So I’m creating an infinite world. To do this, I’m spawning “tiles”, and each tile spawns objects on it (such as trees, rocks etc…). However, when playing you can feel a hiccup as a tile gets spawned. A quick look in the Profiler points to Mesh.Bake PhysX CollisionData being the culprit:
After some looking around, I found a setting in the Player Settings called “Prebake Collision Meshes”. I thought “Great, I’m saved!”. In the Editor, it makes no difference, so I thought OK, let’s build it for Android. I run it with the Profiler connected and “Prebake Collision Meshes” enabled, and there are still hickups from Mesh.Bake (see screenshot above from the Android device WITH Prebake enabled).
What am I supposed to do if that button doesn’t seem to work?
Also, that brings me to another point: I’m spawning only 1 type of tree right now. ALL trees are identical. So why is it calculating a mesh for each tree when all of them are the same? Is that an optimization oversight by UT? If so, can I get around this via scripting?
Thanks for any ideas!
EDIT: I unchecked “Inflate Mesh” and now what used to take 120ms now takes 10ms. A huge improvement! So I guess Inflate Mesh isn’t baked in when “Prebake Collision Meshes” is enabled? Is this normal or a bug?
I guess if I was good in 3D modeling programs, I could take a mesh, inflate it there, then re-import it and have a mesh collider use the pre-inflated mesh (basically avoid using Unity’s mesh inflator). Very hairy but in theory that would work. I don’t see why inflated meshes can’t be baked.
That would slightly explain things, as if the Skin Width was changed in-game, the pre-baked data would be useless. However, that could be fixed by having a “Prevent runtime changes to mesh collider” checkbox that would prevent you from changing the skin width while the game is running. So I hope the Mesh Collider gets revisited and that extra feature is added.
Has this been re-visited? The inflate feature is excellent for generating low poly collision geometry for meshes in our game. We don’t expect to be able to inflate and deflate at runtime.
I think that we’re actually deprecating this flag with the PhysX 3.4 upgrade because we switch to the Quickhull algorithm for building convexes. There will be a spin-off build soon, once 2018.2 goes beta.
I see. It would be a shame to loose the inflate functionality, even if it was just a static helper method on the Mesh class. var inflatedMesh = Mesh.Inflate(myMesh, inflateAmount);
The inflation was a nice and quick way to programmatically generate convex low-poly mesh colliders.
Though I think the inflate functionality is a part of PhysX and not Unity, so it may not be possible to ‘expose’ this function to us?
Not sure this is a good use for it really. Inflation increases volume, and you get the described effect of lower faces in a convex only with the extreme values I believe. Though a possible case, I’d think this was never the design intention.
I encountered this problem when enabling ‘Prebake Collision Meshes’ from the Player settings. PhysX ignores the inflated mesh and tries to use the gameObject mesh. In my case, that resulted in a lot of failures due to more than 255 faces. I was forced to create simpler versions in Maya.
A search on the asset store shows a few people who have tried to tackle this issue. One example:
Another:
What would be really amazing is if Unity dropped dependancy on the PhysX engine and looked at other options, like Bullet or Havok.