# Update InstancedMesh geometry and material

**URL:** <https://discourse.threejs.org/t/update-instancedmesh-geometry-and-material/31345>\
**Category:** Questions\
**Tags:** materials, instanced-mesh, geometry\
**Created:** [November 1, 2021, 9:49am UTC](https://discourse.threejs.org/t/update-instancedmesh-geometry-and-material/31345 "2021-11-01T09:49:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Xillez](https://avatars.discourse-cdn.com/v4/letter/x/bc8723/32.png) [@Xillez](https://discourse.threejs.org/u/Xillez)\
**Post date:** [November 1, 2021, 9:49am UTC](https://discourse.threejs.org/t/update-instancedmesh-geometry-and-material/31345/1 "2021-11-01T09:49:46Z")

</div>

Hello!

Is it possible to update an instanced mesh with new geometries and materials after creation?

For example:

```javascript
const geometry = new THREE.BoxGeometry(1, 1, 1);
const material = new THREE.MeshBasicMaterial({ color: 0x00ff00 });
const test = new THREE.InstancedMesh(geometry, material, 9);
test.instanceMatrix.setUsage(THREE.DynamicDrawUsage); // will be updated every frame
this.scene.add(test);
for (let i = 0; i < 9; i++) {
  const pos = new THREE.Vector3(Math.random() * 3, Math.random() * 3, Math.random() * 3);
  const rot = new THREE.Quaternion();
  const scale = new THREE.Vector3(1, 1, 1);
  test.setMatrixAt(i, new THREE.Matrix4().compose(pos, rot, scale));
}
setTimeout(() => {
  const geometry2 = new THREE.SphereGeometry(15, 32, 16);
  const material2 = new THREE.MeshBasicMaterial({ color: 0x0000ff });
  test.geometry = geometry2;
  test.material = material2;
  this.render();
}, 15000);

```

---

<div class="post-metadata">

**Author:** ![Mugen87](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/mugen87/32/5645_2.png) [@Mugen87](https://discourse.threejs.org/u/Mugen87)\
**Post date:** [November 1, 2021, 10:32am UTC](https://discourse.threejs.org/t/update-instancedmesh-geometry-and-material/31345/2 "2021-11-01T10:32:01Z")

</div>

I’ve tested it here and it works as expected: [Edit fiddle - JSFiddle - Code Playground](https://jsfiddle.net/47dvoLc9/)

You should also call `dispose()` on the previous geometry and material if you are going to replace them.

---

<div class="post-metadata">

**Author:** ![Xillez](https://avatars.discourse-cdn.com/v4/letter/x/bc8723/32.png) [@Xillez](https://discourse.threejs.org/u/Xillez)\
**Post date:** [November 1, 2021, 12:00pm UTC](https://discourse.threejs.org/t/update-instancedmesh-geometry-and-material/31345/3 "2021-11-01T12:00:11Z")

</div>

Yes I will. Sorry, small blunder on my part. They didn’t show up due to the replacing sphere’s size, causing the camera to be inside 🤦‍♂️

Thanks for the help anyway!
