Vertices color not updating

Hi there, i have a strange problem. I create a custom BufferGeometry (made by myself, it’s called CustomWireframeGeometry) to create a sort of wireframe of quads for meshes. In this geometry i set only position and color attributes and then i construct a LineSegments mesh. After that i want to change colors of the edges of this geometry on hover with raycasting.
I’m able to get the index of the edge to change vertices color, but it doesn’t work.
These piece of codes may help:

//create the custom wireframe
const geometry = new THREE.BoxGeometry( 20, 20, 20 );
const wireframe = new CustomWireframeGeometry( geometry );       //custom geometry that extends BufferGeometry
var lineMaterial = new THREE.LineBasicMaterial({color: 0xffffff,vertexColors: true});
const line = new THREE.LineSegments( wireframe,lineMaterial );

...

//and then on intersection from the raycaster i call this function
setLineColor : function(intersected,color){ //intersected is the intersected object of the raycaster
            var index = intersected.index;
            const colorAttribute = intersected.object.geometry.getAttribute("color");
            colorAttribute.setXYZ(index,color.r,color.g,color.b);
            colorAttribute.setXYZ(index + 1,color.r,color.g,color.b);
            colorAttribute.needsUpdate = true;
}

As you can see i set needsUpdate to true for the color attribute, but nothing changes…
Can anyone help me please?
Thank you very much in advance

Do you mind demonstrating the issue with a live example? three.js dev template - module - JSFiddle - Code Playground

Ok i tried, here it is:

Thank you very much!

TBH, I’m not sure why it does not work with your custom geometry. I’ve tried EdgesGeometry for testing and everything works as expected: https://jsfiddle.net/dhk59quf/

What irritates me is the number of vertices of your custom wireframe geometry. The displayed wireframe for the cube should have 12 edges which means 24 vertices. The instance of CustomWireframeGeometry has 48 however. It did not have the time to inspect the vertex data but maybe you are drawing the edges twice and thus do not see the highlight of only one edge.

You’re right i’ll rewrite my custom geometry to draw the edges only one time, now it seems to duplicate them.
Thank you very much for pointing me in the right direction!