Mesh.onAfterRenderObservable not called before material is ready

When using clipPlanes, the suggested way to clip one mesh is to set scene.clipPlane in onBeforeRenderObservable and to clear it in onAfterRenderObservable.
But when the mesh has a material which is not currently ready on first render, the onBeforeRenderObservable is called but the onAfterRenderObservable is not, causing other meshes being clipped.

Screenshot:

Playground:

Note: keep the playground page focused when loading to reproduce.

Hmmm could an acceptable solution be to use onReadyObservable to check when clipping can be started? Mesh.onAfterRenderObservable not called before material is ready | Babylon.js Playground (babylonjs.com)

There’s a new way to do it since one of the latest version (I don’t remember which one): use the clipPlaneX properties of the material. See Material | Babylon.js Documentation

No need for onBefore/AfterRenderObservable doing it this way.

2 Likes