Lock a property on script A when script B is added?

I’m not sure if this is correct, but I’m working on a script that would change the color of both a light component and a sprite renderer component (to the same value or a mapping of the same value).

Because of this I want to specify it only once (and I believe it makes sense to do so in this new script I’m writting, but that’s besides the point). In doing this, however, I’m allowing the value to be changed in the light and spriterenderer scripts, despite the fact that they will be overwritten.

Is it possible to create a custom editor that will lock the color property of these two scripts when my specific script is added?

As a work-around I’m also overwritting these values with the OnValidate() callback, but I’d still like to do this if possible.

I would try changing it to this:

 public Material defaultMaterial;
 public Material activatedMaterial;
 public SpriteRenderer sr;
 public Light2D light;
  
 private void SetValues(Material material) {
     sr.material = material;
     sr.material.color = material.color;
     light.color = material.color;
 }

As I’m not too sure on double declaring a material, so it’s best to keep them separate. But your main problem was that you were declaring the default material to be placed, so instead just change the input parameter as the value to change :slight_smile: @nmiguel123