# With WebGPU, material.setFloat() in onBeforeRender causes mesh to disappear

**URL:** <https://forum.babylonjs.com/t/with-webgpu-material-setfloat-in-onbeforerender-causes-mesh-to-disappear/57467>\
**Category:** Bugs\
**Tags:** webgpu, shader-material\
**Created:** [March 28, 2025, 10:01am UTC](https://forum.babylonjs.com/t/with-webgpu-material-setfloat-in-onbeforerender-causes-mesh-to-disappear/57467 "2025-03-28T10:01:05Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![HiGreg](https://avatars.discourse-cdn.com/v4/letter/h/c5a1d2/32.png) [@HiGreg](https://forum.babylonjs.com/u/HiGreg)\
**Post date:** [March 28, 2025, 10:01am UTC](https://forum.babylonjs.com/t/with-webgpu-material-setfloat-in-onbeforerender-causes-mesh-to-disappear/57467/1 "2025-03-28T10:01:05Z")

</div>

When using WebGPU, material.setFloat() in scene.onBeforeRenderObservable causes mesh to disappear.

The fix is to add a delay of 1-2 seconds after mesh.onReady triggers, before adding the observer.

I don’t have a simple playground that shows the error, as the mesh setup is fairly extensive. I’ll post a playground if I can get one.

I’m using ShaderMaterial with a custom shader. The mesh is over 11000 vertices and has a custom VerticesKind, a large uniform (a matrix for each vertex), and the error-causing float uniform.

Before setting the BeforeRender observable, all the following are true:

- mesh onMeshReady has triggered
- material.isReady
- RawTexture.isReady
- material onCompile has triggered

Pseudocode:

- create and fill TypedArrays containing data
- new Mesh
- mesh.setVerticesData
- new ShaderMaterial
- material.setFloat
- new RawTexture
- material.setTexture
- mesh material = material
- mesh.onMeshReadyObservable.add ({scene.onBeforeRenderObservable.add { mesh.material.setFloat() } })

The only difference between working and not working is if I setTimeout with at LEAST 500ms delay after mesh is ready before adding the render observer that calls setFloat(). On my machine, 2000ms is reliable.

I’m very new to ShaderMaterial. Is there anything obvious in the functions I’m using or the sequence that would cause the error?

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [March 28, 2025, 4:08pm UTC](https://forum.babylonjs.com/t/with-webgpu-material-setfloat-in-onbeforerender-causes-mesh-to-disappear/57467/2 "2025-03-28T16:08:05Z")

</div>

Hey there  
It is tough to help without a repro in the Playground ;(

cc @Evgeni_Popov

---

<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:** [March 28, 2025, 5:20pm UTC](https://forum.babylonjs.com/t/with-webgpu-material-setfloat-in-onbeforerender-causes-mesh-to-disappear/57467/3 "2025-03-28T17:20:10Z")

</div>

Yes, I think a repro will be mandatory, because by itself, `setFloat` doesn’t do anything:

> <https://github.com/BabylonJS/Babylon.js/blob/master/packages/dev/core/src/Materials/shaderMaterial.ts#L317-L322>

---

<div class="post-metadata">

**Author:** ![HiGreg](https://avatars.discourse-cdn.com/v4/letter/h/c5a1d2/32.png) [@HiGreg](https://forum.babylonjs.com/u/HiGreg)\
**Post date:** [March 29, 2025, 6:08am UTC](https://forum.babylonjs.com/t/with-webgpu-material-setfloat-in-onbeforerender-causes-mesh-to-disappear/57467/4 "2025-03-29T06:08:50Z")

</div>

I tried to repro, but I instead created a demo of 800000 random elliptical orbits around earth using orbit parameters within the range of actual satellite parameters.

white = circular, cyan = eccentric

> **[Babylon.js Playground](https://playground.babylonjs.com/#2HLC0W)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL and WebGPU 3D scenes

1000000 doesn’t work on my machine (it loses context). 800000 runs at about 70-80 fps on my machine.

There must be something else going on in my main code that is causing it to fail.

Edit: main code includes another mesh for thinInstancing (witno thininstances) and a mesh with url texture (earth image wrapped around sphere, I think 4k or 8k). It _seems_ like the failure could result from async loading or compiling that, because of activity, delays the readiness of the offending mesh/texture. I need to collect more evidence before asking to spend more core developer time.
