Remove mesh from highlight layer

Dear Forum

I’ve added a highlight layer, but i can’t remove any meshes from it after adding them.
The playground is from somebody else, who did a “hili._meshes = [];” at the end to remove the highlights. But i can’t use that, as the materials are all black afterwards.

Playground: (click on the ground should make the highlights disapear)
https://playground.babylonjs.com/#129LNB#19

Thank you!

removeIncludedMesh does not exist, you had some errors in the console log:

https://playground.babylonjs.com/#129LNB#21

yes thank you sorry

https://playground.babylonjs.com/#129LNB#20

so it works like this. In my use case the actual problem seems to be the root parent from the gltf import. root.getChildren() ist not working - i have to search for some other ways to adress the meshes within the root parent

I think the PG you linked is ok?

here’s a repo of the problem:

https://www.babylonjs-playground.com/#WGZLGJ#1577
&
https://www.babylonjs-playground.com/#WGZLGJ#1578

Why does it work here?:
https://www.babylonjs-playground.com/#1KUJ0A#102

Don’t call removeMesh with a string but with an actual pointer to the mesh:

https://www.babylonjs-playground.com/#WGZLGJ#1579

1 Like

thank you - great!

Ps: removing all meshes from the highlight layer at once don’t seems to be possible so far:

so i did it like that:

for (var i=0;i<scene.meshes.length;i++) {
var mesh = scene.meshes[i];
highlightsLayer.removeMesh(mesh);
}

You can use removeAllMeshes() we added for this.