# Mesh.onAfterRenderObservable not called before material is ready

**URL:** <https://forum.babylonjs.com/t/mesh-onafterrenderobservable-not-called-before-material-is-ready/36994>\
**Category:** Bugs\
**Tags:** material, mesh\
**Created:** [December 30, 2022, 5:08am UTC](https://forum.babylonjs.com/t/mesh-onafterrenderobservable-not-called-before-material-is-ready/36994 "2022-12-30T05:08:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kzhsw](https://avatars.discourse-cdn.com/v4/letter/k/848f3c/32.png) [@kzhsw](https://forum.babylonjs.com/u/kzhsw)\
**Post date:** [December 30, 2022, 5:08am UTC](https://forum.babylonjs.com/t/mesh-onafterrenderobservable-not-called-before-material-is-ready/36994/1 "2022-12-30T05:08:50Z")

</div>

When using [clipPlanes](https://doc.babylonjs.com/features/featuresDeepDive/scene/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](https://github.com/BabylonJS/Babylon.js/blob/81ed63be0f0d6716591a3751ec7a866fb0edbf72/packages/dev/core/src/Meshes/mesh.ts#L2200) but the `onAfterRenderObservable ` [is not](https://github.com/BabylonJS/Babylon.js/blob/81ed63be0f0d6716591a3751ec7a866fb0edbf72/packages/dev/core/src/Meshes/mesh.ts#L2221-L2248), causing other meshes being clipped.

Screenshot:

 ![图片](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/1/6/16342df55354d1ea3d052c9c10341c05f9af52fc.png)

Playground:

> **[Babylon.js Playground](https://playground.babylonjs.com/#EHLHNX%2398)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

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

---

<div class="post-metadata">

**Author:** ![carolhmj](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/carolhmj/32/25918_2.png) [@carolhmj](https://forum.babylonjs.com/u/carolhmj)\
**Post date:** [December 30, 2022, 11:01am UTC](https://forum.babylonjs.com/t/mesh-onafterrenderobservable-not-called-before-material-is-ready/36994/2 "2022-12-30T11:01:53Z")

</div>

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)](https://playground.babylonjs.com/#EHLHNX#99)

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [December 31, 2022, 1:48pm UTC](https://forum.babylonjs.com/t/mesh-onafterrenderobservable-not-called-before-material-is-ready/36994/3 "2022-12-31T13:48:21Z")

</div>

> [@kzhsw](#):
>
> When using [clipPlanes](https://doc.babylonjs.com/features/featuresDeepDive/scene/clipPlanes), the suggested way to clip one mesh is to set `scene.clipPlane` in `onBeforeRenderObservable` and to clear it in `onAfterRenderObservable`.

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](https://doc.babylonjs.com/typedoc/classes/BABYLON.Material#clipPlane)

No need for onBefore/AfterRenderObservable doing it this way.
