Drag-and-drop generated model clicks cannot be highlighted


This is a drag-and-drop model, and then I click on these models, and I can’t get the grid to highlight, and this is a report error。

This is the code, the drag-and-drop generated model click doesn’t seem to be able to be highlighted, and an error is reported。

Can you repro on the Playground?

  • It’s no use putting it on the playground without knowing what the situation is

Without playground or more code it will be hard to help you…

https://playground.babylonjs.com/#M6YS14#6
I added a line of code in there, so the model created by click and drop cannot change the color。
scene.onPointerDown = function (evt, pickResult) {
console.log(evt);
console.log(pickResult);
// let hl = new BABYLON.HighlightLayer(“hl1”, scene);
// hl.addMesh(pickResult.pickedMesh, BABYLON.Color3.Green());
var myMaterial = new BABYLON.StandardMaterial(“myMaterial”, scene);
myMaterial.diffuseColor = new BABYLON.Color3(1, 0, 1);
pickResult.pickedMesh.material = myMaterial;
}

1 Like

This is the playground, I added a line of code, but the error, can not use, can help me solve

  • This is the playground. Can you help me? Thank you very much

It is because you are using instances so the material is shared with the parent. You should try to rely on a clone in your PG.

1 Like

Do you have similar code? I want to see it, because I’m a little bit confused, can you post a piece of code

replace the

newInstance = models["test"].createInstance("skull_" + instCount);

with

newInstance = models["test"].clone("skull_" + instCount);

@sebavan
could you give me some further informations just for understanding? :nerd_face:
instances share the material…ok, but why can’t I modify it like the clone?

The main point of instances is to render them all in one draw call so the same material is use for all instances.

With clone, we do save time in setup but as we do each clone with a separate draw call, you can specify independant materials setup.

1 Like
  • You were really good. You helped me out
1 Like

thanks for making this more clear!