Author Topic: Need help on the Multiple No Flask from Liquid Volume script  (Read 53 times)

eganki

  • Newbie
  • *
  • Posts: 6
    • View Profile
Need help on the Multiple No Flask from Liquid Volume script
« on: December 30, 2020, 11:44:44 AM »
Hi,

I've encountered a problem when the Fill Level in Multiple No Flask did not work as expected.

Expected:
https://drive.google.com/file/d/1FMXxqoq9OwCRkXyCCIDqtxrqBHjpbSXe/view?usp=sharing
Result:
https://drive.google.com/file/d/1hDeptgjePAFyl_ibMznmrh2VG_oxUZF9/view?usp=sharing

As you can see, the fill level suddenly drop from 0.175 to 0.125 and I can't find a way to edit the fill level variable itself.

Thanks for your time and look forward to your reply.

Kronnect

  • Administrator
  • Hero Member
  • *****
  • Posts: 6521
    • View Profile
Re: Need help on the Multiple No Flask from Liquid Volume script
« Reply #1 on: December 30, 2020, 12:29:06 PM »
When using the multiple variant, the fill level is no longer editable. You need to specify a different amount for each layer and the resulting fill level is automatically calculated based on the amount and density of each layer.

This code setups a 4 layer liquid:

Code
        void FourLayersExample() {
LiquidVolume.LiquidLayer[] layers = new LiquidVolume.LiquidLayer[4];
layers[0].amount = 0.25f;
layers[0].density = 1f;
layers[1].amount = 0;
layers[1].density = 1f;
layers[2].amount = 0;
layers[2].density = 1f;
layers[3].amount = 0;
layers[3].density = 1f;
layers[0].color = new Color(1, 0, 0);
layers[1].color = new Color(0, 1, 0);
layers[2].color = new Color(0, 0, 1);
layers[3].color = new Color(0.5f, 0.5f, 0.5f);
lv.liquidLayers = layers;
lv.UpdateLayers();
}

This other code sets random properties for the existing layers:

Code
		void SetRandomProperties() {

            int layerCount = lv.liquidLayers.Length;
            if (layerCount == 0)
                return;

            float fillLevel = 0;
            for (int k = 0; k < layerCount; k++) {
                float layerAmount = (1.0f - fillLevel) * Random.value;
                fillLevel += layerAmount;
                lv.liquidLayers[k].amount = layerAmount;
                lv.liquidLayers[k].bubblesOpacity = Random.value;
                lv.liquidLayers[k].color = new Color(Random.value, Random.value, Random.value, Random.value);
                lv.liquidLayers[k].murkColor = new Color(Random.value, Random.value, Random.value, Random.value);
                lv.liquidLayers[k].murkiness = Random.value;
            }
            // Immediately update layers
            lv.UpdateLayers(true);

        }

This code is taken from the BakerController.cs script located in Demos/Multiple Layers/DemoResources/Scripts folder.





eganki

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Need help on the Multiple No Flask from Liquid Volume script
« Reply #2 on: January 04, 2021, 01:14:06 PM »
Hi,
Thanks for the quick reply.

As you can see from the video, I am currently only using one layer in the test tube, and halfway through the animation, I've modified both values from Bubbles opacity and the Amount. This issue will not occur if I am using Default No Flask setting.

I am not sure if either one of the function; OnValidate() or OnDidApplyAnimationProperties() from our previous discussion are the ones causing this bug. Still, I was hoping through here that we can find a way to stop the auto calculation and set the value ourselves.

eganki

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Need help on the Multiple No Flask from Liquid Volume script
« Reply #3 on: January 04, 2021, 07:14:23 PM »
Hi,

I noticed if I set Bubbles opacity lower than one, it will work as intended in animation.
I'll continue to test around and see what I can find.