Warning to all my friends: BEWARE Optimise Mesh Data!!

I just spent several days trying to figure out why I kept getting an error when combining a specific mesh, only in build. It was SO strange, since it was only due to that mesh, and doing certain things would “fix” it, but in an incredibly strange manner.

Turns out I stupidly enabled “Optimize Mesh Data” (Strip Unused Mesh Components) in the player settings without knowing what exactly it does.

Edit: turns out its on by default, so it wasn’t stupidity

Soo yeah if you’re having strange issues with meshes, try this simple trick! And don’t randomly enable features without knowing what they do. :^)

I’ll go back to banging my head against the wall.

Good luck :3

Related note, it’d be cool to have the option to choose what components are stripped, sort of like how you can choose what vertices are compressed.

7 Likes

Thanks for the warning, but uh, isn’t it common sense? Do we need to be told that pressing things without knowing what they do cause problems? Honestly?

BRB someone said I had to type in format c:/

4 Likes

Kinda meant to be an ironic post lmao

2 Likes

I also had a problem with “Optimize Mesh Data” that took quite a few hours to figure out. I was loading Normal Maps at runtime, and they wouldn’t show in the build because that feature was enabled.

3 Likes

Isn’t it enabled by default?

9 Likes

Irony.

I do not think that word means what you think it means!

Regardless, thanks for the heads up.

Scary part is Windows 10 just asks if you’re positive you want to format. I wasn’t crazy enough to hit Y to see what would happen on my main system. If I had a VM with snapshots handy I would totally have tried it. :stuck_out_tongue:

1 Like

meanie

9 Likes

We are getting a bit derailed.

I just checked. The checkbox is on by default. So I don’t think the OP “stupidly” enabled it. It was always enabled.

It used to be very safe to leave on, but (semi)recently they changed its behaviour and it has been known to obliterate more data than it should (I have filed at least one bug report on this).

9 Likes

I knew it. When I saw in alerts that Ony had quoted my post, I KNEW I was gonna get told off. I dunno how, just knew.

1 Like

hah! <3

1 Like

Interesting to hear this wasn’t my fault lol

1 Like

We just encountered this issue ourselves! We have meshes for the ‘characters’ in our game that contain special ‘skinning’ data in UV0, UV1, UV2, etc. (Skinning as in ‘ingame cosmetics’ ). We have different shaders for different skins that make use of the various different UV channels for different effects.

The character mesh is assigned to the character prefabs mesh filter. The mesh renderer on the character prefab has a default material that only uses UV0. At runtime, we swap out the material to different ones that use UV1, UV2, etc. It works fine in the editor, but when the game is built these additional channels are stripped out since Unity thinks that the mesh will only be rendered with a shader that uses UV0.

It seems like this assumption is fine in most cases, we’d love to keep Optimize Mesh Data turned on, but there is no way to tell it to exclude meshes from the Optimization process so we have no choice but to turn it off for the entire project, just because of a handful of meshes that need to retain their UV channels.

The alternative way is to have a scene that contains every character mesh withe very possible material assigned to each of the meshes, and to include this scene with the build so that Unity wont strip out the channels, but that doesn’t seem worth the effort for us. (size between optimisation on and off was about 2mbs for us, so not worth this hassle to save 2mb)

6 Likes

Same issue with me. Spent an hour to find that this was the cause of incorrect half4 texcoord3 UV mapping on Android (using 4 UV channels in custom CG shader)… when turned off, everything works. It didn’t exclude UVs, just some coords were incorrect.

Have you tried to disable it for the entire project and write an AssetPostprocessor that removes unneeded mesh data, following whatever rules are needed in your project, instead?

That way “optimize mesh data” would work even inside the editor and you have per asset control.

4 Likes

thanks a lot, It saves my day

1 Like

Million Thanks! Take me loooong time to figure it out before I saw this post.

1 Like

fixed my mesh color problem, there were zero colors on my mesh on build.

1 Like

I think mesh optimization should be disabled by default. Messing with mesh data without our knowing is kinda frustrating!

2 Likes

But ‘optimize mesh data’ sounds so harmless and downright optimal - who wouldn’t press it? Unity needs a ‘do not press this button’ button.

5 Likes