Unexpected Batching Interaction with Preload - Documentation

This might be something that would be a useful addition to the batching documentation. I was using the PlayCanvas profiler to keep an eye on draw calls and I realized the 68 grass meshes I thought I batched were actually adding 68 draw calls. I checked all the situations from the docs where batching wouldn’t work as expected, but following the docs, the batching should be working. After some messing around, it turns out turning off preload on a batched mesh prevents batching. Which from a coding standpoint if the batch operation is running on load, that makes sense now that I think of it, but still a gotcha I didn’t expect.

Hi @Chris,

Indeed the batcher will run automatically when the app starts and later only when a model component gets enabled. This should be useful to have in the docs, agreed.

For other cases you will have to run the batcher manually.

I was gonna say running on enable/disable would be convenient. I did some testing, and because I’m doing the enable/disable on the parent of the batched meshes, the batcher never runs.

I’ve just done a test with the following setup:

  • a number of cube models with their parent disabled
  • all assigned to a static batch group

Running the app and after a while enabling the parent entity triggers the batcher, as expected.

1 Like

Thank you for the quick response and investigating it as well. I created a similar test project and I realized what’s happening. I have some meshes that are disabled by default when the application starts up, that’s why I have preload turned off. When it comes time to show these meshes, for whatever reason since they were initially disabled, when I enable them for the first time the batcher will not run. However, if I start with these meshes enabled the batcher runs, and if I start with them disabled, then enable, disable, and enable a second time, the second time the batcher will run, just not the first time. Weird lol.

Test project here: https://playcanvas.com/project/702118/overview/batching-test (My account is full, please ignore the fact I’m using my co’s account :wink:)
You can see the effect by enabling/disabling the “test” entity.

To be honest, I’d love to have an option where the batcher doesn’t run at all automatically.

Sometimes enabling a single entity and having the batcher re-run for the whole group can slow down the app considerably.

To that end I’d say the app can’t easily understand when all the assets for a batch group are ready for batching when preload is set to false. So maybe this isn’t so much a bug, but it’s like this by design.

Otherwise you will get random runs of the batcher while the app is already running. And that can potentially add a large number of lost frames, since it takes a while for the batcher to finish.

1 Like