Tools ‐ Mesh batcher - ow-mods/outer-wilds-unity-wiki GitHub Wiki

Purpose

Batching is used to increase performance, at the cost of bigger meshes (more memory and disk usage).

If you have a lot of individual renderers, Unity can struggle because it has to individually tell the GPU to draw each one (and the CPU to calculate bounds). Packaging them up into a single mesh means Unity only has to do one bounds calculation and one draw. Even with the same amount of triangles, this is considerably faster.

Same thing goes for colliders: Unity is faster at single complex colliders VS many simple ones.

IF you or others experience lag when looking at pieces of your world, consider batching. If you can, use the profiler to see what parts are causing slowdown instead of blindly guessing.

[!WARNING]
Batching literally everything into a single mesh is also bad for performance, because Unity will have to render the entire mesh even if only a small piece of it can be seen. A balance must be struck between how much is batched and how many batch meshes there are.

Base game tends to keep batch sizes moderate and spatially local (e.g. single buildings, patches of grass, trees for an area).

Usage

Add the Mesh Batch script to an object. Clicking the button will batch the GameObjects under it and place a new GameObject with the new renderers and colliders.

You can also use Tools > Batch All to batch any MeshBatch scripts in the current editing environment.

[!WARNING]
Any non-renderer or collider components will not be carried over to the batched GameObject. You must move these to another GameObject.

[!WARNING]
GameObjects with a negative scale will have triangles that render inside-out. This is because it flips the triangle winding order, which determines which triangle face is the front and the back. I don't know how to fix this.

A few of the Nomai Ruins pieces have negative scale :( I do not want to fix it.

[!WARNING]
Currently, the non-batched version of your stuff will be inactive (so you can unbatch if needed), but still built into your AssetBundle. This is not a huge deal, but still something I would like to fix.

Git note

You may have to run git config core.longpaths true to commit the batched mesh files, as they have long names. (The names are that way to ensure uniqueness across different prefabs.)

A good metric for if your batches are WAYYY too big is if it doesn't fit into the GitHub file limit (100 mb).