Hello
I have two blend shape values (Height_Max and Height_Min) that I want to set on the same UI slider. Both of their values go from 0 to 100.
On the UI slider, I want the Height_Max value to be set to 0 to 100. Also, I want the Height_Min value to be set to 0 to -100.
But I don’t know how to assign a specific range for both of these values so they work on the same slider. I also don’t know how to convert the Height_Min’s value of 0 to 100 to be 0 to -100 instead.
Would anyone happen to know how to do this? Thanks in advanced and sorry if this is a simple question. I looked for awhile and couldn’t find anything.
A slider can only have one value, so I assume you want to drive two internal values from a single slider’s value.
You can just set the slider itself to return one of those ranges, such as 0 to 100.
Then each time it returns that value, you would:
-
use the 0 to 100 for Height_Max (unchanged)
-
you would compute the other value and set it to Height_Min.
For “Compute” it looks like you are either subtracting 100, or else you are negating the quantity, but obviously you can put any function you want to compute one from the other.
Thanks for your help! That’s correct, I do want to set two internal values to one slider.
I have it set up like this in my code so I can set up the two blend shape parameters in OnValueChanged:
public void SliderBlendInfoMax(int blendNum)
{
skinnedMesh.SetBlendShapeWeight(blendNum, currentSlider.value);
}
public void SliderBlendInfoMin(int blendNum)
{
//here is where I want to convert the blendshape value of 0 to 100 into 0 to -100 on the slider
skinnedMesh.SetBlendShapeWeight(blendNum, currentSlider.value);
}
But yes the Height_Max works since it’s the default value.
I tried doing this:
public void SliderBlendInfoMin(int blendNum)
{
skinnedMesh.GetBlendShapeWeight(Mathf.Clamp(currentSlider.value, 0, -100));
skinnedMesh.SetBlendShapeWeight(blendNum, -currentSlider.value);
}
But Mathf.Clamp doesn’t seem to work with integers, only floats.
Use caution : line 3 above says “GET” not “SET”
Also, it’s always best to pluck out the value from currentSlider.value and put it into a variable.
From that variable, compute the OTHER variable.
Now you have those two you can:
Air your code out vertically, one thing per line… think “Social distancing for your code.”
Haha I like social distancing for the code. Thank you for the tips!!
I did get it working like this instead of plucking out the currentSlider.value:
public void SliderBlendInfoMax(int blendNum)
{
if(currentSlider.value >= 0)
{
skinnedMesh.SetBlendShapeWeight(blendNum, currentSlider.value);
}
else
{
skinnedMesh.SetBlendShapeWeight(blendNum, 0);
}
}
public void SliderBlendInfoMin(int blendNum)
{
if(currentSlider.value <= 0)
{
skinnedMesh.SetBlendShapeWeight(blendNum, -currentSlider.value);
}
else
{
skinnedMesh.SetBlendShapeWeight(blendNum, 0);
}
}
It does work, do you think that it’s alright?
If it solves your problem and gives correct output, SHIP IT!
1 Like
Awesome, thanks so much for your help!! You’re so helpful on these forums!!
1 Like