playcanvas / editor

Issue tracker for the PlayCanvas Editor
https://playcanvas.com/
154 stars 28 forks source link

Changing materials on Entities that share materials, changes the wrong Entity #1002

Closed yaustar closed 1 year ago

yaustar commented 1 year ago

Video of bug which explains this better than I can

https://user-images.githubusercontent.com/16639049/224710427-b76ec0bb-ee99-4058-9cfe-eb82de3c648f.mp4

Repro steps:

  1. Fork and open https://playcanvas.com/project/1049509/overview/material-bug
  2. Select entity play2
  3. Select entity play1
  4. Remove the material on play1
  5. See that the material is removed on play2 instead

I believe there's an issue here where the both render components are using the same material reference

yaustar commented 1 year ago

Found the issue. When one entity is selected and then the next one is selected, if the values in the materials array are the same, the bindings aren't updated to link to the new Entity due to this line:

https://github.com/playcanvas/pcui/blob/main/src/components/ArrayInput/index.ts#L549

So the current component inspector with the material when the next entity is selected is still binded/linked to the previous entity hence this behaviour

slimbuck commented 1 year ago

That's some great detective work @yaustar!