# UVs not updating on Mesh despite all vertexData kinds being set to updatable?

**URL:** <https://forum.babylonjs.com/t/uvs-not-updating-on-mesh-despite-all-vertexdata-kinds-being-set-to-updatable/17705>\
**Category:** Questions\
**Tags:** material, engine\
**Created:** [January 21, 2021, 8:20pm UTC](https://forum.babylonjs.com/t/uvs-not-updating-on-mesh-despite-all-vertexdata-kinds-being-set-to-updatable/17705 "2021-01-21T20:20:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ultralowpoly](https://avatars.discourse-cdn.com/v4/letter/u/e9bcb4/32.png) [@ultralowpoly](https://forum.babylonjs.com/u/ultralowpoly)\
**Post date:** [January 21, 2021, 8:20pm UTC](https://forum.babylonjs.com/t/uvs-not-updating-on-mesh-despite-all-vertexdata-kinds-being-set-to-updatable/17705/1 "2021-01-21T20:20:30Z")

</div>

UVs not updating on Mesh despite all vertexData kinds being set to updatable?  
[https://playground.babylonjs.com/#ZNGJG1](https://playground.babylonjs.com/#ZNGJG1)

```
var createScene = function () {
var scene = new BABYLON.Scene(engine);
var camera = new BABYLON.ArcRotateCamera("Camera", 3 * Math.PI / 2, Math.PI / 4, 8, BABYLON.Vector3.Zero(), scene);
camera.attachControl(canvas, true);
var light = new BABYLON.HemisphericLight("hemi", new BABYLON.Vector3(1, 1, 0), scene);
light.intesity = 0.5;

var positions = [
    -4, 0, 4,
    4, 0, 4,
    4, 0, -4,
    -4, 0, -4,
    -3, 0, 1,
    -1, 0, 1,
    -1, 0, -1,
    -3, 0, -1,
    -2.5, 1, 0.5,
    -1.5, 1, 0.5,
    -1.5, 1, -0.5,
    -2.5, 1, -0.5,
    1, 0, 1,
    3, 0, 1,
    3, 0, -1,
    1, 0, -1,
    2, 1.5, 0,
    -3, 0, 4,
    -1, 0, 4,
    1, 0, 4,
    3, 0, 4,
    3, 0, -4,
    1, 0, -4,
    -1, 0, -4,
    -3, 0, -4
];

var indices = [
    9, 8, 10,
    8, 11, 10,
    8, 4, 11,
    11, 4, 7,
    8, 5, 4,
    8, 9, 5,
    9, 10, 5,
    10, 6, 5,
    10, 7, 6,
    10, 11, 7,
    16, 12, 15,
    16, 13, 12,
    16, 14, 13,
    16, 15, 14,
    4, 18, 17,
    4, 5, 18,
    5, 19, 18,
    5, 12, 19,
    5, 6, 15,
    5, 15, 12,
    12, 20, 19, 
    12, 13, 20,
    13, 1, 20,
    13, 2, 1,
    13, 14, 2,
    14, 21, 2,
    14, 22, 21,
    14, 15, 22,
    15, 23, 22,
    15, 6, 23, 
    6, 24, 23,
    7, 24, 6,
    7, 3, 24, 
    7, 0, 3,
    7, 4, 0,
    4, 17, 0
];

//take uv value relative to bottom left corner of roof (-4, -4) noting length and width of roof is 8
// base uv value on the x, z coordinates only
var uvs = [];
for(var p = 0; p < positions.length / 3; p++) {
    uvs.push((positions[3 * p] - (-4)) / 8, (positions[3 * p + 2] - (-4)) / 8);
}

var customMesh = new BABYLON.Mesh("custom", scene);
customMesh.markVerticesDataAsUpdatable(BABYLON.VertexBuffer.PositionKind, true);
customMesh.markVerticesDataAsUpdatable(BABYLON.VertexBuffer.UVKind, true);
customMesh.markVerticesDataAsUpdatable(BABYLON.VertexBuffer.UV2Kind, true);
customMesh.markVerticesDataAsUpdatable(BABYLON.VertexBuffer.UV3Kind, true);
customMesh.markVerticesDataAsUpdatable(BABYLON.VertexBuffer.UV4Kind, true);
customMesh.markVerticesDataAsUpdatable(BABYLON.VertexBuffer.UV5Kind, true);
customMesh.markVerticesDataAsUpdatable(BABYLON.VertexBuffer.UV6Kind, true);
customMesh.markVerticesDataAsUpdatable(BABYLON.VertexBuffer.ColorKind, true);
customMesh.markVerticesDataAsUpdatable(BABYLON.VertexBuffer.MatricesIndicesKind, true);
customMesh.markVerticesDataAsUpdatable(BABYLON.VertexBuffer.MatricesIndicesExtraKind, true);
customMesh.markVerticesDataAsUpdatable(BABYLON.VertexBuffer.MatricesWeightsKind, true);
customMesh.markVerticesDataAsUpdatable(BABYLON.VertexBuffer.MatricesWeightsExtraKind, true);

var normals = []; //Empty array to contain calculated values or normals added
BABYLON.VertexData.ComputeNormals(positions, indices, normals); //Calculations of normals added

var vertexData = new BABYLON.VertexData();
vertexData.positions = positions;
vertexData.indices = indices;
vertexData.normals = normals; //Assignment of normal to vertexData added
vertexData.uvs = uvs;
vertexData.applyToMesh(customMesh);

var mat = new BABYLON.StandardMaterial("", scene);
mat.diffuseTexture = new BABYLON.Texture("textures/co.png")
customMesh.material = mat;

setTimeout(()=>{
    for(var p = 0; p < positions.length / 3; p++) {
        uvs.push(Math.abs(Math.random()), Math.abs(Math.random()));
    }
    //vertexData.uvs = uvs;
    //vertexData.applyToMesh(customMesh);
    customMesh.updateVerticesData(BABYLON.VertexBuffer.UVKind, uvs);
    customMesh.setVerticesData(BABYLON.VertexBuffer.UVKind, uvs);
}, 3000);

return scene;

```

}

---

<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:** [January 21, 2021, 10:27pm UTC](https://forum.babylonjs.com/t/uvs-not-updating-on-mesh-despite-all-vertexdata-kinds-being-set-to-updatable/17705/2 "2021-01-21T22:27:25Z")

</div>

It seems to me you are not resetting the uvs array so you are simply adding at the end of it instead of restarting at the beginning

---

<div class="post-metadata">

**Author:** ![JohnK](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/johnk/32/26764_2.png) [@JohnK](https://forum.babylonjs.com/u/JohnK)\
**Post date:** [January 21, 2021, 10:41pm UTC](https://forum.babylonjs.com/t/uvs-not-updating-on-mesh-despite-all-vertexdata-kinds-being-set-to-updatable/17705/3 "2021-01-21T22:41:59Z")

</div>

Also once you change the data did you see this in the docs .

_Note:_ When creating your own custom mesh to make it updatable you need to add a second parameter with value true when applying the mesh to the vertex data.

---

<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:** [January 21, 2021, 11:17pm UTC](https://forum.babylonjs.com/t/uvs-not-updating-on-mesh-despite-all-vertexdata-kinds-being-set-to-updatable/17705/4 "2021-01-21T23:17:25Z")

</div>

Fix: [UVs Updating Not Working | Babylon.js Playground](https://playground.babylonjs.com/#ZNGJG1#2)
