Why is it shared when I change the color of the object I clicked using the color picker?

Hi there:)

I have a question.

As the title says, why is it shared color when I change the color of the object I clicked using the color picker?

I think I changed the color by approaching the material of the clicked mesh, is that not it?
(link below)

It doesn’t even work in a real work environment (line 46, 47)
so I have to change like below because of TS

if(clickedMesh.material?.diffuseTexture) {
let mat = clickedMesh.material.diffuseTexture as StandardMaterial;
mat = null;
mat.diffuseColor = value;

What am I supposed to do?

Please let me know

Thanks in advance.

Hello and welcome!

If you mat = null you will have null.diffuseTexture which is also would be just null if it has any sense…
You don’t change the material, you need to change only its properties.
Here your example works - https://www.babylonjs-playground.com/#0XC1MH#2

Thank you for your answer.

However, the texture was treated as null intentionally.

click the left rabbit to change the color, and then click the right rabbit to change the color, and the color of the two rabbits will still change at the same time.

I want to change the color of individual rabbits.

That seems odd, isn’t it? :slight_smile:

Color Change Test | Babylon.js Playground (babylonjs-playground.com)

For the sake of reusability we use the same vector when notifying of a value change. When you set this vector to be the color of one mesh, changing it again will set the other mesh’s color again.

Pinging @DarraghBurke to maybe find an elegant way to avoid reusing (for example with a flag?) though this is the expected behavior. Maybe documenting it will be enough :slight_smile:

1 Like

Edit: ignore me, Raanan has the correct solution here!

Thank you for your reply. I’ll have to come up with another idea and apply it :grin:


You can use the method i showed in the corrected playground. It’s the simplest and will work well in all scenarios

1 Like

I guess I confused you because I’m not good at English. I solved it the way you told me.
Have a nice day :+1: