playcanvas / playcanvas/engine

Non-preloaded batched objects aren't batched on enable (first enable only)

Open
#2,314 2 comments 0 reactions 1 assignee View on GitHub

@mvaligursky is already working on this.

Since Jul 25, 2020.

area: graphics
Dominant language
JavaScript
Stars
16.8k
Forks
2k
Avg merge
4h 32m
Merged PRs (30d)
222

Description

Description

Basically, when you enable the entity of a batched model that is not preloaded, the model will not be batched. However, if you disable, then re-enable that same entity, the batching will run the second time around. This is unexpected behavior for what I imagine is a somewhat common use-case.

Use-case

You have a batched model in your scene that you enable later on. Natually, you turn off preload to speed up app load. When you later enable that model, despite being batched it won't actually be batched.

This is confusing behavior with batching working perfectly fine when you have a preloaded object, but breaking for seemingly no reason when you turn off preload. The batching documentation does not mention this behavior, which adds to the mystery.

Solutions

I'm not sure what the intended behavior is, I understand batching on enable is a bit of a convenience method and if an asset isn't preloaded, the batcher would need events for each batched asset to run once it's loaded. But, I think there should be some consistency, if we're going to automatically load the child models of an entity I think it would be reasonable to expect that batching would be similarly generated automatically. However, Leonidas mentioned he would prefer more control over when the batcher runs and have it default to run less, so in that case I think for consistency's sake it would make sense to never automatically batch when entities are enabled (could potentially break apps).

Regardless, I think this would be a useful "gotcha" to the batching documentation.

Steps to Reproduce

This test project can be used to reproduce this behavior.

  1. Add a handful models (that can be batched) to the scene under a single parent entity.
  2. Uncheck "preload" on these models.
  3. In the editor, setup batching across all these models.
  4. Disable the parent entity.
  5. Launch the scene preview (with the profiler).
  6. In the editor, re-enable the parent entity.
  7. Observe that the models that were just added are not being batched according to the draw calls.
  8. In the editor, disable the parent entity, and then re-enable the parent entity (again).
  9. Observe that this time the draw calls will indicate the models are now being batched.

On the otherhand, if you check "preload" on these models, when you first load the scene they will be batched.

Screenshots
Models were enabled after the scene was loaded - note the 29 draw calls
image

Models were disabled and then re-enabled - now draw calls are 5
image

PlayCanvas forum discussion: https://forum.playcanvas.com/t/unexpected-batching-interaction-with-preload-documentation/13942/4

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.