How to dispose a pbr material and keep the effect cache?

I just update from v6 to v8 and I notice my effect is disposed by the pr.

Now even if I set forceDisposeEffect to false when disposing the pbr material, the effect will always be disposed because [mesh’s material change] → [mesh call resetDrawCache] →[effect disposed by drawCache’s dispose]. So the param forceDisposeEffect is not in use actually.

notBoundToMesh seems to work but it is not used in pbrMaterial nor standardMaterial.

As a description, I dispose the material and create it again just as a quick way to dispose the textures.

Playground: Babylon.js Playground , you’ll see a obvious flicker when changing the material in v8 because of the rebuild of the effect, and it works fine in v6.

You can use BABYLON.Effect.PersistentMode = true; to avoid disposing an effect when the effect is disposed (and refcount is 0):

https://playground.babylonjs.com/#PZIMMM

1 Like

Thanks this do work! But then forceDisposeEffect lost its use, maybe we should mark it as deprecated?

No, it is used internally to force the removal of all effects when engine.releaseEffects() is called. Also, there may be other uses…

Thanks for the explaination, I went through the code and found it is deprecated already as it is not used in material.dispose().