Scaled Variables

Hi everyone,

I have a question about scaling variables to one and other.

If I was to have a set of variables inside of a scriptable object ie:

[Range(0,1)]
float a;
[Range(0,1)]
float b;
[Range(0,1)]
float c;
[Range(0,1)]
float d;

and so on, is there a way I can link them together so that the combined variables are used as a percentage of each out of a whole.
So I could have all 5 as 0.2 and then adjust one to be 0.4 and the others would drop to 0.15 automatically.

Is this possible or is there a better option that someone else can see that I cannot.

Thank you!

Implement the OnValidate() method. It gets called whenever you change the values in the inspector. You can normalize the values there.
If all you want is to have the sum of them all to be 1, you could try

protected void OnValidate()
{
    float sum = a + b+ c + d;
    a /= sum;
    b /= sum;
    c /= sum;
    d /= sum;
}

This might not be perfect, because it will also keep changing the value you are trying to set. You’d want to detect which one it is, and keep it out of the validation. I don’t think you can detect that easily from OnValidate, but you could write a custom Editor / PropertyDrawer

I’ve had to fully create a custom method and change the entire process. Will make things a lot more difficult further down the line, but it’s the only way to keep going for now.
Thank you for the input!